
Allan Nielsen wrote:
Hi again,
I have now tried to get your suggested solution to work, but did not succeed.
template<typename Archive> void serialize(Archive &ar, const unsigned int) { auto * data_ptr = &data; ar & data_ptr; // load and save through pointer
if(Archive::is_loading::value) { data = std::move(*data_ptr); // no-throw ar.reset_object_address(&data, data_ptr); delete data_ptr; // not sure here }
This produced a compiler error, so I slitted it into separated load and save methods which looks like this:
BOOST_SERIALIZATION_SPLIT_MEMBER();
template<class Archive> void save(Archive & ar, const unsigned int version) const { const std::vector<unsigned> * data_ptr = &data; ar & data_ptr; // load and save through pointer }
template<class Archive> void load(Archive & ar, const unsigned int version) { const vector<int> * data_ptr; ar & data_ptr; // load and save through pointer data = std::move(*data_ptr); // no-throw ar.reset_object_address(&data, data_ptr); delete data_ptr; }
This whole thing looks a little suspicious to me. I'd have to spend considerable time looking into it. But I'm curious why you don't just do the following: template<class Archive> void save(Archive &ar, const unsigned int version) const { ar << data; } template<class Archive> void load(Archive &ar, const unsigned int version){ ar >> data; }
Also, if I add:
BOOST_STATIC_ASSERT( (boost::serialization::tracking_level< const std::vector<unsigned> * >::value != boost::serialization::track_never) );
I get an compiler error saying static assert failed. Why is that? shouldn't everything serialized through a pointer be tracked?
again, I'd have to look into this more deeply. I'm a little intriqued with serilization of
const vector<int> * data_ptr;
I guess it's ok but it's sort of wierd to load a pointer to a CONST. Robert Ramey
What can I do to fix this?
Best regards Allan W. Nielsen _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users