53879

Boost Serialization - Serialize std::tr1::shared_ptr?

Boost::Serialization has builtin support for boost::shared_ptr<>.

Is there a way to use this support for std::tr1::shared_ptr<> too? Is it possible to cast from std::tr1::shared_ptr<> to boost::shared_ptr<>?

Answer1:

A casting will not be possible as implementations differ. Also creating an instance of the one shared_ptr type with the value returned from get() on the other shared_ptr type will not work correctly as the reference countings will go to 0 at different points in your code which leads to deletion of the object before the last use of it. I am not an expert of boost::serialization but as the interfaces of std::tr1::shared_ptr<> and boost::shared_ptr<> are nearly identical it is very likely that you can just clone the serialization/deserialization code of boost::shared_ptr<> and only have to replace the namespace of the shared_ptr.

Recommend

  • conversion of array to string
  • what's the size of std::tr1::array >
  • Constant-sized vector
  • How to get localized Windows Administrators group name in Inno Setup?
  • Strange file-permissions if apps run as administrator
  • Multiple Dispatch with Generics
  • OpenCV imread with foreign characters
  • Dynamic UI from JSON object
  • What is the difference between CacheStoreMode USE and REFRESH
  • How to have a difference in week units between two days (even if they're close but belong to di
  • Wiring top-level DAGs together
  • Cast uint -> double invalid?
  • using pinentry-tty in a bash script (like read)
  • Google API - Redirect URI mismatch error
  • Why won't EF4 generate a method to support my Function Import?
  • When interface inheritance in Java is useful?
  • RavenDB indexing errors
  • Multiple Left Join LINQ-to-entities
  • runtime-check whether an instance (Base*) override a parent function (Base::f())
  • Suqueries in select clause with JPA
  • Building Qt project for C++11 standard
  • C++ friend class std::vector
  • Error in installing package: fatal error: stdlib.h: no such file or directory
  • Default parameter as generic type
  • C++ pointer value changes with static_cast
  • Exception “firebase.functions() takes … no argument …” when specifying a region for a Cloud Function
  • C++ Partial template specialization - design simplification
  • Highlight one bar in a series in highcharts?
  • Initializer list vs. initialization method
  • Control modification in presentation layer
  • Sails.js/waterline: Executing waterline queries in toJSON function of a model?
  • Fetching methods from BroadcastReceiver to update UI
  • Calling of Constructors in a Java
  • PHP: When would you need the self:: keyword?
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • How do I configure my settings file to work with unit tests?
  • How to get Windows thread pool to call class member function?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Reading document lines to the user (python)
  • Binding checkboxes to object values in AngularJs