jeudi 24 août 2017

Serializing a class with std::mt19937_64 member using Boost::Serialization

Given a class definition

class Example {
    std::mt19937_64 rng_;
;}

how to serialize it using Boost? I tried

class Example { 
    std::mt19937_64 rng_;
    template <class Archive> void save(Archive& ar, const unsigned int version) const {
        ar << rng_;
    }

    template <class Archive> void load(Archive& ar, const unsigned int version) {
        ar >> rng_;
    }
    BOOST_SERIALIZATION_SPLIT_MEMBER();
;}

but it doesn't work - the state of rng_ member is not read back from the archive.




Aucun commentaire:

Enregistrer un commentaire