
"Pavel Vozenilek" <pavel_vozenilek@hotmail.com> wrote in message news:c6head$r3r$1@sea.gmane.org...
"Jeff Flinn" <TriumphSprint2000@hotmail.com> wrote:
While the current methods for Free Functions and Splitting save/load methods are certainly understandable and work. It would be nice to be able (partial)specialize the "serialize" function base on its IO type. It
would
also be nice to utilize enable_if to generate different code when the serialize function is instantiated for input/output archives. This would allow compile time constructs similar to mfc's runtime Ar.IsLoad().
template<typename Archive> bool is_saving(const Archive& arch) { return boost::is_base_and_derived<boost::archive::basic_oarchive, Archive>::value; }
Can be used like:
template<typename Archive> void serialize(Archive & ar, const unsigned int version) { ar & value_1; ... ar & value_n if (is_saving(ar)) { ... } else { .. } ar & value_n+1; ... }
Thanks Pavel! template<typename Archive> bool is_saving ( const Archive& ) { return boost::is_base_and_derived<boost::archive::basic_oarchive,Archive>::value; } template<typename Archive> bool is_loading( const Archive& ) { return boost::is_base_and_derived<boost::archive::basic_iarchive,Archive>::value; } This condenses the boost::filesystem::path save/load to a single serialize: namespace boost { namespace serialization { template<class Archive> inline void serialize( Archive& ar , boost::filesystem::path& t , unsigned int version ) { std::string lPathString; if( is_saving(ar) ) lPathString = t.native_file_string(); ar & make_nvp( "PathString", lPathString ); if( is_loading(ar) ) t = boost::filesystem::path( lPathString, boost::filesystem::native ); } } } This is even more attractive for more complex classes with only a few split members. Robert, would these function be able to be added to the library? Jeff F