]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/serialization/test/test_set_boost_unordered.cpp
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>
20 #if defined(BOOST_NO_STDC_NAMESPACE)
26 #include <boost/detail/workaround.hpp>
27 #if defined(BOOST_NO_STDC_NAMESPACE)
33 #include <boost/archive/archive_exception.hpp>
35 #include "test_tools.hpp"
37 #include <boost/serialization/nvp.hpp>
38 #include <boost/serialization/set.hpp>
43 #include <boost/serialization/boost_unordered_set.hpp>
44 #include <functional> // requires changeset [69520]; Ticket #5254
49 std::size_t operator()(const A
& a
) const {
50 return static_cast<std::size_t>(a
);
57 const char * testfile
= boost::archive::tmpnam(NULL
);
58 BOOST_REQUIRE(NULL
!= testfile
);
60 // test array of objects
61 boost::unordered_set
<A
> anunordered_set
;
63 anunordered_set
.insert(a
);
64 anunordered_set
.insert(a1
);
66 test_ostream
os(testfile
, TEST_STREAM_FLAGS
);
67 test_oarchive
oa(os
, TEST_ARCHIVE_FLAGS
);
68 oa
<< boost::serialization::make_nvp("anunordered_set", anunordered_set
);
70 boost::unordered_set
<A
> anunordered_set1
;
72 test_istream
is(testfile
, TEST_STREAM_FLAGS
);
73 test_iarchive
ia(is
, TEST_ARCHIVE_FLAGS
);
74 ia
>> boost::serialization::make_nvp("anunordered_set", anunordered_set1
);
76 std::vector
<A
> tvec
, tvec1
;
79 std::copy(anunordered_set
.begin(), anunordered_set
.end(), std::back_inserter(tvec
));
80 std::sort(tvec
.begin(), tvec
.end());
81 std::copy(anunordered_set1
.begin(), anunordered_set1
.end(), std::back_inserter(tvec1
));
82 std::sort(tvec1
.begin(), tvec1
.end());
83 BOOST_CHECK(tvec
== tvec1
);
84 std::remove(testfile
);
88 test_unordered_multiset(){
89 const char * testfile
= boost::archive::tmpnam(NULL
);
90 BOOST_REQUIRE(NULL
!= testfile
);
92 boost::unordered_multiset
<A
> anunordered_multiset
;
93 anunordered_multiset
.insert(A());
94 anunordered_multiset
.insert(A());
96 test_ostream
os(testfile
, TEST_STREAM_FLAGS
);
97 test_oarchive
oa(os
, TEST_ARCHIVE_FLAGS
);
98 oa
<< boost::serialization::make_nvp("anunordered_multiset", anunordered_multiset
);
100 boost::unordered_multiset
<A
> anunordered_multiset1
;
102 test_istream
is(testfile
, TEST_STREAM_FLAGS
);
103 test_iarchive
ia(is
, TEST_ARCHIVE_FLAGS
);
104 ia
>> boost::serialization::make_nvp("anunordered_multiset", anunordered_multiset1
);
107 std::vector
<A
> tvec
, tvec1
;
110 std::copy(anunordered_multiset
.begin(), anunordered_multiset
.end(), std::back_inserter(tvec
));
111 std::sort(tvec
.begin(), tvec
.end());
112 std::copy(anunordered_multiset1
.begin(), anunordered_multiset1
.end(), std::back_inserter(tvec1
));
113 std::sort(tvec1
.begin(), tvec1
.end());
114 BOOST_CHECK(tvec
== tvec1
);
116 std::remove(testfile
);
119 int test_main( int /* argc */, char* /* argv */[] ){
120 test_unordered_set();
121 test_unordered_multiset();