]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/bimap/test/test_bimap_project.cpp
6b66127e56c610c6f015915322ee5191beca9342
[ceph.git] / ceph / src / boost / libs / bimap / test / test_bimap_project.cpp
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 https://web.archive.org/web/20071014014301/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 // Boost.Test
21 #include <boost/test/minimal.hpp>
22
23 #include <string>
24
25 // Boost.Bimap
26 #include <boost/bimap/bimap.hpp>
27 #include <boost/bimap/list_of.hpp>
28
29 using namespace boost::bimaps;
30
31 struct left_tag {};
32 struct right_tag {};
33
34 void test_bimap_project()
35 {
36 typedef bimap
37 <
38 tagged< int , left_tag >,
39 list_of< tagged< std::string, right_tag > >
40
41 > bm_type;
42
43 bm_type bm;
44
45 bm.insert( bm_type::value_type(1,"1") );
46 bm.insert( bm_type::value_type(2,"2") );
47
48 bm_type:: iterator iter = bm.begin();
49 bm_type:: left_iterator left_iter = bm.left.find(1);
50 bm_type::right_iterator right_iter = bm.right.begin();
51
52 const bm_type & cbm = bm;
53
54 bm_type:: const_iterator citer = cbm.begin();
55 bm_type:: left_const_iterator left_citer = cbm.left.find(1);
56 bm_type::right_const_iterator right_citer = cbm.right.begin();
57
58 // non const projection
59
60 BOOST_CHECK( bm.project_up (bm.end()) == bm.end() );
61 BOOST_CHECK( bm.project_left (bm.end()) == bm.left.end() );
62 BOOST_CHECK( bm.project_right(bm.end()) == bm.right.end() );
63
64 BOOST_CHECK( bm.project_up (iter) == iter );
65 BOOST_CHECK( bm.project_left (iter) == left_iter );
66 BOOST_CHECK( bm.project_right(iter) == right_iter );
67
68 BOOST_CHECK( bm.project_up (left_iter) == iter );
69 BOOST_CHECK( bm.project_left (left_iter) == left_iter );
70 BOOST_CHECK( bm.project_right(left_iter) == right_iter );
71
72 BOOST_CHECK( bm.project_up (right_iter) == iter );
73 BOOST_CHECK( bm.project_left (right_iter) == left_iter );
74 BOOST_CHECK( bm.project_right(right_iter) == right_iter );
75
76 bm.project_up ( left_iter)->right = "u";
77 bm.project_left (right_iter)->second = "l";
78 bm.project_right( iter)->first = "r";
79
80 // const projection
81
82 BOOST_CHECK( cbm.project_up (cbm.end()) == cbm.end() );
83 BOOST_CHECK( cbm.project_left (cbm.end()) == cbm.left.end() );
84 BOOST_CHECK( cbm.project_right(cbm.end()) == cbm.right.end() );
85
86 BOOST_CHECK( cbm.project_up (citer) == citer );
87 BOOST_CHECK( cbm.project_left (citer) == left_citer );
88 BOOST_CHECK( cbm.project_right(citer) == right_citer );
89
90 BOOST_CHECK( cbm.project_up (left_citer) == citer );
91 BOOST_CHECK( cbm.project_left (left_citer) == left_citer );
92 BOOST_CHECK( cbm.project_right(left_citer) == right_citer );
93
94 BOOST_CHECK( cbm.project_up (right_citer) == citer );
95 BOOST_CHECK( cbm.project_left (right_citer) == left_citer );
96 BOOST_CHECK( cbm.project_right(right_citer) == right_citer );
97
98 // mixed projection
99
100 BOOST_CHECK( bm.project_up (left_citer) == iter );
101 BOOST_CHECK( bm.project_left (left_citer) == left_iter );
102 BOOST_CHECK( bm.project_right(left_citer) == right_iter );
103
104 BOOST_CHECK( cbm.project_up (right_iter) == citer );
105 BOOST_CHECK( cbm.project_left (right_iter) == left_citer );
106 BOOST_CHECK( cbm.project_right(right_iter) == right_citer );
107
108 bm.project_up ( left_citer)->right = "u";
109 bm.project_left (right_citer)->second = "l";
110 bm.project_right( citer)->first = "r";
111
112 // Support for tags
113
114 BOOST_CHECK( bm.project< left_tag>(iter) == left_iter );
115 BOOST_CHECK( bm.project<right_tag>(iter) == right_iter );
116
117 BOOST_CHECK( bm.project< left_tag>(left_iter) == left_iter );
118 BOOST_CHECK( bm.project<right_tag>(left_iter) == right_iter );
119
120 BOOST_CHECK( bm.project< left_tag>(right_iter) == left_iter );
121 BOOST_CHECK( bm.project<right_tag>(right_iter) == right_iter );
122
123 BOOST_CHECK( cbm.project< left_tag>(citer) == left_citer );
124 BOOST_CHECK( cbm.project<right_tag>(citer) == right_citer );
125
126 BOOST_CHECK( cbm.project< left_tag>(left_citer) == left_citer );
127 BOOST_CHECK( cbm.project<right_tag>(left_citer) == right_citer );
128
129 BOOST_CHECK( cbm.project< left_tag>(right_citer) == left_citer );
130 BOOST_CHECK( cbm.project<right_tag>(right_citer) == right_citer );
131
132 bm.project< left_tag>(right_citer)->second = "l";
133 bm.project<right_tag>( left_citer)->first = "r";
134
135 }
136
137
138 int test_main( int, char* [] )
139 {
140 test_bimap_project();
141 return 0;
142 }
143