1 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
4 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
5 // (C) Copyright 2014 Jim Bell
6 // Use, modification and distribution is subject to the Boost Software
7 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
10 // should pass compilation and execution
12 #include <cstddef> // NULLsize_t
13 #include <cstdio> // remove
16 #include <algorithm> // std::copy
19 #include <boost/config.hpp>
21 #include <boost/detail/workaround.hpp>
22 #if defined(BOOST_NO_STDC_NAMESPACE)
29 #include "test_tools.hpp"
31 #include <boost/serialization/nvp.hpp>
32 #include <boost/serialization/hash_set.hpp>
37 #ifndef BOOST_HAS_HASH
38 #error "BOOST_HAS_HASH not defined!"
41 #include BOOST_HASH_SET_HEADER
43 namespace BOOST_STD_EXTENSION_NAMESPACE
{
46 std::size_t operator()(const A
& a
) const {
47 return static_cast<std::size_t>(a
);
54 const char * testfile
= boost::archive::tmpnam(NULL
);
55 BOOST_REQUIRE(NULL
!= testfile
);
57 // test array of objects
58 BOOST_STD_EXTENSION_NAMESPACE::hash_set
<A
> ahash_set
;
63 test_ostream
os(testfile
, TEST_STREAM_FLAGS
);
64 test_oarchive
oa(os
, TEST_ARCHIVE_FLAGS
);
65 oa
<< boost::serialization::make_nvp("ahash_set", ahash_set
);
67 BOOST_STD_EXTENSION_NAMESPACE::hash_set
<A
> ahash_set1
;
69 test_istream
is(testfile
, TEST_STREAM_FLAGS
);
70 test_iarchive
ia(is
, TEST_ARCHIVE_FLAGS
);
71 ia
>> boost::serialization::make_nvp("ahash_set", ahash_set1
);
73 std::vector
<A
> tvec
, tvec1
;
76 std::copy(ahash_set
.begin(), ahash_set
.end(), std::back_inserter(tvec
));
77 std::sort(tvec
.begin(), tvec
.end());
78 std::copy(ahash_set1
.begin(), ahash_set1
.end(), std::back_inserter(tvec1
));
79 std::sort(tvec1
.begin(), tvec1
.end());
80 BOOST_CHECK(tvec
== tvec1
);
81 std::remove(testfile
);
86 const char * testfile
= boost::archive::tmpnam(NULL
);
87 BOOST_REQUIRE(NULL
!= testfile
);
89 BOOST_STD_EXTENSION_NAMESPACE::hash_multiset
<A
> ahash_multiset
;
90 ahash_multiset
.insert(A());
91 ahash_multiset
.insert(A());
93 test_ostream
os(testfile
, TEST_STREAM_FLAGS
);
94 test_oarchive
oa(os
, TEST_ARCHIVE_FLAGS
);
95 oa
<< boost::serialization::make_nvp("ahash_multiset", ahash_multiset
);
97 BOOST_STD_EXTENSION_NAMESPACE::hash_multiset
<A
> ahash_multiset1
;
99 test_istream
is(testfile
, TEST_STREAM_FLAGS
);
100 test_iarchive
ia(is
, TEST_ARCHIVE_FLAGS
);
101 ia
>> boost::serialization::make_nvp("ahash_multiset", ahash_multiset1
);
104 std::vector
<A
> tvec
, tvec1
;
107 std::copy(ahash_multiset
.begin(), ahash_multiset
.end(), std::back_inserter(tvec
));
108 std::sort(tvec
.begin(), tvec
.end());
109 std::copy(ahash_multiset1
.begin(), ahash_multiset1
.end(), std::back_inserter(tvec1
));
110 std::sort(tvec1
.begin(), tvec1
.end());
111 BOOST_CHECK(tvec
== tvec1
);
113 std::remove(testfile
);
116 int test_main( int /* argc */, char* /* argv */[] ){
118 test_hash_multiset();