Index: libs/serialization/test/test_map.cpp =================================================================== --- libs/serialization/test/test_map.cpp (revision 69571) +++ libs/serialization/test/test_map.cpp (working copy) @@ -147,7 +147,7 @@ template<> struct hash{ std::size_t operator()(const random_key& r) const { - return (std::size_t)r; + return static_cast(r); } }; } // namespace BOOST_STD_EXTENSION_NAMESPACE @@ -216,6 +216,85 @@ } #endif +#include +#include // requires changeset [69520]; Ticket #5254 + +namespace std { +namespace tr1 { + + template<> + struct hash{ + std::size_t operator()(const random_key& r) const { + return static_cast(r); + } + }; +} // namespace tr1 +} // namespace std + +void +test_unordered_map(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + BOOST_CHECKPOINT("unordered_map"); + // test unordered_map of objects + std::tr1::unordered_map anunordered_map; + anunordered_map.insert(std::make_pair(random_key(), A())); + anunordered_map.insert(std::make_pair(random_key(), A())); + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("anunorderedmap",anunordered_map); + } + std::tr1::unordered_map anunordered_map1; + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("anunorderedmap",anunordered_map1); + } + + std::vector< std::pair > tvec, tvec1; + std::copy(anunordered_map.begin(), anunordered_map.end(), std::back_inserter(tvec)); + std::sort(tvec.begin(), tvec.end()); + std::copy(anunordered_map1.begin(), anunordered_map1.end(), std::back_inserter(tvec1)); + std::sort(tvec1.begin(), tvec1.end()); + BOOST_CHECK(tvec == tvec1); + + std::remove(testfile); +} + +void +test_unordered_multimap(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + BOOST_CHECKPOINT("unordered_multimap"); + std::tr1::unordered_multimap anunordered_multimap; + anunordered_multimap.insert(std::make_pair(random_key(), A())); + anunordered_multimap.insert(std::make_pair(random_key(), A())); + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("anunordered_multimap", anunordered_multimap); + } + std::tr1::unordered_multimap anunordered_multimap1; + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("anunordered_multimap", anunordered_multimap1); + } + std::vector< std::pair > tvec, tvec1; + tvec.clear(); + tvec1.clear(); + std::copy(anunordered_multimap.begin(), anunordered_multimap.end(), std::back_inserter(tvec)); + std::sort(tvec.begin(), tvec.end()); + std::copy(anunordered_multimap1.begin(), anunordered_multimap1.end(), std::back_inserter(tvec1)); + std::sort(tvec1.begin(), tvec1.end()); + BOOST_CHECK(tvec == tvec1); + std::remove(testfile); +} + + int test_main( int /* argc */, char* /* argv */[] ) { test_map(); @@ -225,5 +304,7 @@ test_hash_map(); test_hash_multimap(); #endif + test_unordered_map(); + test_unordered_multimap(); return EXIT_SUCCESS; } Index: libs/serialization/test/test_set.cpp =================================================================== --- libs/serialization/test/test_set.cpp (revision 69571) +++ libs/serialization/test/test_set.cpp (working copy) @@ -94,7 +94,7 @@ template<> struct hash { std::size_t operator()(const A& a) const { - return (std::size_t)a; + return static_cast(a); } }; } @@ -164,6 +164,86 @@ } #endif +#include +#include // requires changeset [69520]; Ticket #5254 + + +namespace std { +namespace tr1 { + template<> + struct hash { + std::size_t operator()(const A& a) const { + return static_cast(a); + } + }; +} // namespace tr1 +} // namespace std + +void +test_unordered_set(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + // test array of objects + std::tr1::unordered_set anunordered_set; + A a, a1; + anunordered_set.insert(a); + anunordered_set.insert(a1); + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("anunordered_set", anunordered_set); + } + std::tr1::unordered_set anunordered_set1; + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("anunordered_set", anunordered_set1); + } + std::vector tvec, tvec1; + tvec.clear(); + tvec1.clear(); + std::copy(anunordered_set.begin(), anunordered_set.end(), std::back_inserter(tvec)); + std::sort(tvec.begin(), tvec.end()); + std::copy(anunordered_set1.begin(), anunordered_set1.end(), std::back_inserter(tvec1)); + std::sort(tvec1.begin(), tvec1.end()); + BOOST_CHECK(tvec == tvec1); + std::remove(testfile); +} + +void +test_unordered_multiset(){ + const char * testfile = boost::archive::tmpnam(NULL); + BOOST_REQUIRE(NULL != testfile); + + std::tr1::unordered_multiset anunordered_multiset; + anunordered_multiset.insert(A()); + anunordered_multiset.insert(A()); + { + test_ostream os(testfile, TEST_STREAM_FLAGS); + test_oarchive oa(os, TEST_ARCHIVE_FLAGS); + oa << boost::serialization::make_nvp("anunordered_multiset", anunordered_multiset); + } + std::tr1::unordered_multiset anunordered_multiset1; + { + test_istream is(testfile, TEST_STREAM_FLAGS); + test_iarchive ia(is, TEST_ARCHIVE_FLAGS); + ia >> boost::serialization::make_nvp("anunordered_multiset", anunordered_multiset1); + } + + std::vector tvec, tvec1; + tvec.clear(); + tvec1.clear(); + std::copy(anunordered_multiset.begin(), anunordered_multiset.end(), std::back_inserter(tvec)); + std::sort(tvec.begin(), tvec.end()); + std::copy(anunordered_multiset1.begin(), anunordered_multiset1.end(), std::back_inserter(tvec1)); + std::sort(tvec1.begin(), tvec1.end()); + BOOST_CHECK(tvec == tvec1); + + std::remove(testfile); +} + + int test_main( int /* argc */, char* /* argv */[] ) { test_set(); @@ -172,5 +252,7 @@ test_hash_set(); test_hash_multiset(); #endif + test_unordered_set(); + test_unordered_multiset(); return EXIT_SUCCESS; }