[random] Saving the state of the random number generator
If I'm using g++ then I can just use operator<< and operator>> to save and load the state of the random number generator. Unfortunately I also need to compile this code on MSVC++ 8.0. Using MSVC++ 8.0 BOOST_NO_MEMBER_TEMPLATE_FRIENDS is defined which removes those operators. Is there some way to do this without modifying mersenne_twister.hpp or doing something crazy like #define private public? Thanks, Jeffrey
Jeffrey A. Edlund wrote:
If I'm using g++ then I can just use operator<< and operator>> to save and load the state of the random number generator. Unfortunately I also need to compile this code on MSVC++ 8.0. Using MSVC++ 8.0 BOOST_NO_MEMBER_TEMPLATE_FRIENDS is defined which removes those operators. Is there some way to do this without modifying mersenne_twister.hpp or doing something crazy like #define private public?
Thanks,
Jeffrey diff -r 45d1d3143fe3 boost/random/mersenne_twister.hpp --- a/boost/random/mersenne_twister.hpp Tue Dec 11 13:26:15 2007 -0500 +++ b/boost/random/mersenne_twister.hpp Mon Dec 17 06:51:24 2007 -0500 @@ -27,6 +27,8 @@ #include
#include #include +#include +#include
namespace boost { namespace random { @@ -152,6 +154,16 @@ public: mt.i = mt.state_size; return is; } + + friend class boost::serialization::access; + + // Serialization + template<class Archive> + void serialize(Archive & ar, const unsigned int /* file_version */){ + ar & serialization::make_nvp ("i", i); + ar & serialization::make_nvp ("x", x); + } + #endif friend bool operator==(const mersenne_twister& x, const mersenne_twister& y)
participants (2)
-
Jeffrey A. Edlund
-
Neal Becker