]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/bimap/test/test_bimap_serialization.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / bimap / test / test_bimap_serialization.cpp
CommitLineData
7c673cae
FG
1// Boost.Bimap
2//
3// Copyright (c) 2006-2007 Matias Capeletto
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8
9// VC++ 8.0 warns on usage of certain Standard Library and API functions that
10// can be cause buffer overruns or other possible security issues if misused.
11// See http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx
12// But the wording of the warning is misleading and unsettling, there are no
13// portable alternative functions, and VC++ 8.0's own libraries use the
14// functions in question. So turn off the warnings.
15#define _CRT_SECURE_NO_DEPRECATE
16#define _SCL_SECURE_NO_DEPRECATE
17
18#include <boost/config.hpp>
19
20// std
21#include <set>
22#include <map>
23#include <cstddef>
24#include <cassert>
25#include <algorithm>
26#include <sstream>
27#include <algorithm>
28
29// Boost.Test
30#include <boost/test/minimal.hpp>
31
32// Boost
33#include <boost/archive/text_oarchive.hpp>
34#include <boost/archive/text_iarchive.hpp>
35
36// Boost.Bimap
37#include <boost/bimap/bimap.hpp>
38
39
40template< class Bimap, class Archive >
41void save_bimap(const Bimap & b, Archive & ar)
42{
43 using namespace boost::bimaps;
44
45 ar << b;
46
47 const typename Bimap::left_const_iterator left_iter = b.left.begin();
48 ar << left_iter;
49
50 const typename Bimap::const_iterator iter = ++b.begin();
51 ar << iter;
52}
53
54
55
56
57void test_bimap_serialization()
58{
59 using namespace boost::bimaps;
60
61 typedef bimap<int,double> bm;
62
63 std::set< bm::value_type > data;
64 data.insert( bm::value_type(1,0.1) );
65 data.insert( bm::value_type(2,0.2) );
66 data.insert( bm::value_type(3,0.3) );
67 data.insert( bm::value_type(4,0.4) );
68
69 std::ostringstream oss;
70
71 // Save it
72 {
73 bm b;
74
75 b.insert(data.begin(),data.end());
76
77 boost::archive::text_oarchive oa(oss);
78
79 save_bimap(b,oa);
80 }
81
82 // Reload it
83 {
84 bm b;
85
86 std::istringstream iss(oss.str());
87 boost::archive::text_iarchive ia(iss);
88
89 ia >> b;
90
91 BOOST_CHECK( std::equal( b.begin(), b.end(), data.begin() ) );
92
93 bm::left_const_iterator left_iter;
94
95 ia >> left_iter;
96
97 BOOST_CHECK( left_iter == b.left.begin() );
98
99 bm::const_iterator iter;
100
101 ia >> iter;
102
103 BOOST_CHECK( iter == ++b.begin() );
104 }
105
106}
107
108
109int test_main( int, char* [] )
110{
111 test_bimap_serialization();
112 return 0;
113}
114