patch to serialize mersenne_twister

Please consider adding this patch to add serialization to mersenne_twister. Since it is only active if BOOST_SERIALIZE_TWISTER is defined, it is completely harmless to those who don't use it.

Neal Becker escribió:
Please consider adding this patch to add serialization to mersenne_twister. Since it is only active if BOOST_SERIALIZE_TWISTER is defined, it is completely harmless to those who don't use it.
There was a discussion in the past about how to provide serialization capabilities and the general opinion was that this is better packaged as a separate header when feasible, something like boost/random/mersenne_twister_serialize.hpp or boost/random/mersenne_twister/serialize.hpp or similar. BTW, it'd be good if we could reach a naming consensus for these serialization files. My favorite is: boost/.../xxx.hpp provides serialization capabilities at boost/.../xxx/serialize.hpp Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

joaquin@tid.es wrote:
Neal Becker escribió:
Please consider adding this patch to add serialization to mersenne_twister. Since it is only active if BOOST_SERIALIZE_TWISTER is defined, it is completely harmless to those who don't use it.
There was a discussion in the past about how to provide serialization capabilities and the general opinion was that this is better packaged as a separate header when feasible, something like
boost/random/mersenne_twister_serialize.hpp
or
boost/random/mersenne_twister/serialize.hpp
or similar. BTW, it'd be good if we could reach a naming consensus for these serialization files. My favorite is:
boost/.../xxx.hpp provides serialization capabilities at boost/.../xxx/serialize.hpp
Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
Since it wants private access into the class, how would you package it as a separate header?

Neal Becker escribió:
joaquin@tid.es wrote:
There was a discussion in the past about how to provide serialization capabilities and the general opinion was that this is better packaged as a separate header when feasible, something like
boost/random/mersenne_twister_serialize.hpp
or
boost/random/mersenne_twister/serialize.hpp
or similar. BTW, it'd be good if we could reach a naming consensus for these serialization files. My favorite is:
boost/.../xxx.hpp provides serialization capabilities at boost/.../xxx/serialize.hpp
Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
Since it wants private access into the class, how would you package it as a separate header?
Something like this: * Header boost/random/mersenne_twister.hpp: namespace boost{namespace random{ template<...> class mersenne_twister; }} namespace boost{namespace serialization{ template<class Archive,...> void serialize( Archive&, boost::random::mersenne_twister<...>&, const unsigned int); }} namespace boost{namespace random{ template<...> class mersenne_twister { //... private: template<class Archive...> friend void boost::serialization::serialize( Archive&, boost::random::mersenne_twister<...>&, const unsigned int); }; }} * Header boost/random/mersenne_twister/serialize.hpp: namespace boost{namespace serialization{ template<class Archive,...> void serialize( Archive& ar, boost::random::mersenne_twister<...>& m, const unsigned int) { ar & serialization::make_nvp ("i", m.i); ar & serialization::make_nvp ("x", m.x); } }} Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

Neal Becker wrote:
Since it wants private access into the class, how would you package it as a separate header?
add "friend class boost::serialization::access;" to the class declaration. Robert Ramey
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Robert Ramey wrote:
Neal Becker wrote:
Since it wants private access into the class, how would you package it as a separate header?
add "friend class boost::serialization::access;" to the class declaration.
Robert Ramey
I don't see how that works. If I add friend class boost::serialization::access; inside of the original class declaration, and then outside the class declaration: typedef boost::mt19937 rng_t; namespace boost { namespace serialization { // Serialization template<class Archive> void serialize(Archive & ar, rng &m, const unsigned int /* file_version */){ ar & serialization::make_nvp ("i", m.i); ar & serialization::make_nvp ("x", m.x); } }} This doesn't compile: /usr/local/src/boost.hg/boost/random/mersenne_twister.hpp:209: error: 'int boost::random::mersenne_twister<unsigned int, 32, 624, 397, 31, 2567483615u, 11, 7, 2636928640u, 15, 4022730752u, 18, 3346425566u>::i' is private mod/boost_rand.cc:49: error: within this context

The common pattern used upto now is to specify serialization in one of two ways: a) For standard library components: "boost/serialization/vector.hpp" - or complex.hpp, etc b) For other libraries "boost/date_time/serialization.hpp" In this way, the macro is redundant. Also, those that don't use serialization don't have any need to even look at the code to verifiy that it is benign as its not even included if they don't need it. Finally, it'll be easier to convince whomever you need to convince to add an optional header to the trunk than to patch some code that someone else will be maintaining. Finally, Finally, such patches (i.e. new headers) should include a new test in order to demonstrate that it is in fact correct. This should be added to the test suite of the particular library - in this case random. Robert Ramey Neal Becker wrote:
Please consider adding this patch to add serialization to mersenne_twister. Since it is only active if BOOST_SERIALIZE_TWISTER is defined, it is completely harmless to those who don't use it.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (3)
-
joaquin@tid.es
-
Neal Becker
-
Robert Ramey