Boost logo

Boost Users :

Subject: [Boost-users] [Serialization] serialization of shared_ptr with custom deleter
From: Elizabeta (elizabeta.petreska_at_[hidden])
Date: 2015-03-26 12:17:04

I am using boost 1.49. There is problem with serialization of shared_ptr
with custom deleter, it doesnot preserve the deleter. After deserialization
of shared_ptr with custom deleter, when using boost::get_deleter on the
deserialized shared_ptr it returns null. Here is code example

struct DetachTest
        int debug =0;
    friend class boost::serialization::access;
    template<class Archive>
    inline void serialize(Archive & ar,
        const unsigned int file_version)

        boost::shared_ptr<DetachTest> ss(new
        std::ofstream ofs("C:\\detach.xml");
        boost::archive::xml_oarchive oa(ofs);
        oa & boost::serialization::make_nvp("detach",ss);


        DetachTest* test = 0;
        boost::shared_ptr<DetachTest> ss (test,SmartDeleter<DetachTest>());
        //del is nonnul here
        SmartDeleter<DetachTest>* del =
boost::get_deleter<SmartDeleter&lt;DetachTest> , DetachTest>(ss);

        std::ifstream ifs("C:\\detach.xml");
        boost::archive::xml_iarchive ia(ifs);
        ia & boost::serialization::make_nvp("detach",ss);
        //de2 is null after deserialization
        SmartDeleter<DetachTest>* de2 =
boost::get_deleter<SmartDeleter&lt;DetachTest> , DetachTest>(ss);

View this message in context:
Sent from the Boost - Users mailing list archive at

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at