diff --git a/include/boost/serialization/shared_ptr_helper.hpp b/include/boost/serialization/shared_ptr_helper.hpp index 276c13a4..a8824365 100644 --- a/include/boost/serialization/shared_ptr_helper.hpp +++ b/include/boost/serialization/shared_ptr_helper.hpp @@ -101,6 +101,26 @@ public: const unsigned int file_version ); #endif + template + struct non_polymorphic { + static const boost::serialization::extended_type_info * + get_object_type(U & ){ + return & boost::serialization::singleton< + BOOST_DEDUCED_TYPENAME + boost::serialization::type_info_implementation< U >::type + >::get_const_instance(); + } + }; + template + struct polymorphic { + static const boost::serialization::extended_type_info * + get_object_type(U & u){ + return boost::serialization::singleton< + BOOST_DEDUCED_TYPENAME + boost::serialization::type_info_implementation< U >::type + >::get_const_instance().get_derived_extended_type_info(u); + } + }; public: template @@ -113,30 +133,12 @@ public: = & boost::serialization::type_info_implementation< T >::type ::get_const_instance(); - struct non_polymorphic { - static const boost::serialization::extended_type_info * - get_object_type(T &){ - return & boost::serialization::singleton< - BOOST_DEDUCED_TYPENAME - boost::serialization::type_info_implementation< T >::type - >::get_const_instance(); - } - }; - struct polymorphic { - static const boost::serialization::extended_type_info * - get_object_type(T & t){ - return boost::serialization::singleton< - BOOST_DEDUCED_TYPENAME - boost::serialization::type_info_implementation< T >::type - >::get_const_instance().get_derived_extended_type_info(t); - } - }; // get pointer to the most derived object's eti. This is effectively // the object type identifer typedef BOOST_DEDUCED_TYPENAME mpl::if_< is_polymorphic< T >, - polymorphic, - non_polymorphic + polymorphic, + non_polymorphic >::type type; const boost::serialization::extended_type_info * true_type diff --git a/test/test_unique_ptr.cpp b/test/test_unique_ptr.cpp index 905e0b47..955cdeaa 100644 --- a/test/test_unique_ptr.cpp +++ b/test/test_unique_ptr.cpp @@ -38,39 +38,28 @@ public: ~A(){} // default destructor }; -void save(const std::unique_ptr & spa, const char *filename) -{ - test_ostream os(filename, TEST_STREAM_FLAGS); - test_oarchive oa(os, TEST_ARCHIVE_FLAGS); - oa << BOOST_SERIALIZATION_NVP(spa); -} - -void load(std::unique_ptr & spa, const char *filename) -{ - test_istream is(filename, TEST_STREAM_FLAGS); - test_iarchive ia(is, TEST_ARCHIVE_FLAGS); - ia >> BOOST_SERIALIZATION_NVP(spa); -} - int test_main(int /* argc */, char * /* argv */[]){ #ifndef BOOST_NO_CXX11_SMART_PTR - const char * testfile = boost::archive::tmpnam(NULL); - BOOST_REQUIRE(NULL != testfile); + const char * filename = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != filename); // create a new auto pointer to ta new object of type A std::unique_ptr spa(new A); - // serialize it - save(spa, testfile); - // reset the auto pointer to NULL - // thereby destroying the object of type A - // note that the reset automagically maintains the reference count - spa.reset(); - // restore state to one equivalent to the original - // creating a new type A object - load(spa, testfile); - // obj of type A gets destroyed - // as auto_ptr goes out of scope - std::remove(testfile); + { + test_ostream os(filename, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << BOOST_SERIALIZATION_NVP(spa); + } + { + // reset the auto pointer to NULL + // thereby destroying the object of type A + // note that the reset automagically maintains the reference count + spa.reset(); + test_istream is(filename, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> BOOST_SERIALIZATION_NVP(spa); + std::remove(filename); + } #endif // BOOST_NO_CXX11_SMART_PTR return EXIT_SUCCESS; }