diff --git a/include/boost/serialization/serialization.hpp b/include/boost/serialization/serialization.hpp index a4d04723c7..2ecf1d79db 100644 --- a/include/boost/serialization/serialization.hpp +++ b/include/boost/serialization/serialization.hpp @@ -11,6 +11,7 @@ #endif #include +#include #include /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 @@ -60,9 +61,36 @@ namespace serialization { BOOST_STRONG_TYPEDEF(unsigned int, version_type) -// default implementation - call the member function "serialize" +// Check whether Type has a serialize() member function that accepts Archive +template +class has_serialize +{ + // This type won't compile if the second template parameter isn't of type T. + template struct type_check; + + typedef char yes; + typedef long no; + + template struct serialize + { + typedef void (T::* fptr)(Archive&, const unsigned int); + }; + + template + static yes check_has_serialize( + type_check< typename serialize::fptr, + &T::serialize/**/ >*); + template + static no check_has_serialize(...); + +public: + static bool const value = (sizeof(check_has_serialize(0)) == sizeof(yes)); +}; + +// default implementation - call the member function "serialize" if it exists, +// else removed from overload resolution. template -inline void serialize( +inline typename boost::enable_if::value>::type serialize( Archive & ar, T & t, const unsigned int file_version ){ access::serialize(ar, t, static_cast(file_version));