]>
Commit | Line | Data |
---|---|---|
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 | #define BOOST_BIMAP_DISABLE_SERIALIZATION | |
21 | ||
22 | // Boost.Test | |
23 | #include <boost/test/minimal.hpp> | |
24 | ||
25 | // std | |
26 | #include <set> | |
27 | #include <map> | |
28 | #include <string> | |
29 | #include <functional> | |
30 | ||
31 | // Set type specifications | |
32 | #include <boost/bimap/set_of.hpp> | |
33 | #include <boost/bimap/multiset_of.hpp> | |
34 | ||
35 | // bimap container | |
36 | #include <boost/bimap/bimap.hpp> | |
37 | ||
38 | #include <libs/bimap/test/test_bimap.hpp> | |
39 | ||
40 | struct left_tag {}; | |
41 | struct right_tag {}; | |
42 | ||
43 | void test_bimap() | |
44 | { | |
45 | using namespace boost::bimaps; | |
46 | ||
47 | typedef std::map<int,double> left_data_type; | |
48 | left_data_type left_data; | |
49 | left_data.insert( left_data_type::value_type(1,0.1) ); | |
50 | left_data.insert( left_data_type::value_type(2,0.2) ); | |
51 | left_data.insert( left_data_type::value_type(3,0.3) ); | |
52 | left_data.insert( left_data_type::value_type(4,0.4) ); | |
53 | ||
54 | typedef std::map<double,int> right_data_type; | |
55 | right_data_type right_data; | |
56 | right_data.insert( right_data_type::value_type(0.1,1) ); | |
57 | right_data.insert( right_data_type::value_type(0.2,2) ); | |
58 | right_data.insert( right_data_type::value_type(0.3,3) ); | |
59 | right_data.insert( right_data_type::value_type(0.4,4) ); | |
60 | ||
61 | ||
62 | //-------------------------------------------------------------------- | |
63 | { | |
64 | typedef bimap< int, double > bm_type; | |
65 | ||
66 | std::set< bm_type::value_type > data; | |
67 | data.insert( bm_type::value_type(1,0.1) ); | |
68 | data.insert( bm_type::value_type(2,0.2) ); | |
69 | data.insert( bm_type::value_type(3,0.3) ); | |
70 | data.insert( bm_type::value_type(4,0.4) ); | |
71 | ||
72 | bm_type bm; | |
73 | test_set_set_bimap(bm,data,left_data,right_data); | |
74 | } | |
75 | //-------------------------------------------------------------------- | |
76 | ||
77 | ||
78 | //-------------------------------------------------------------------- | |
79 | { | |
80 | typedef bimap | |
81 | < | |
82 | multiset_of< tagged<int, left_tag > >, | |
83 | multiset_of< tagged<double, right_tag > >, | |
84 | multiset_of_relation< std::less< _relation > > | |
85 | ||
86 | > bm_type; | |
87 | ||
88 | std::set< bm_type::value_type > data; | |
89 | data.insert( bm_type::value_type(1,0.1) ); | |
90 | data.insert( bm_type::value_type(2,0.2) ); | |
91 | data.insert( bm_type::value_type(3,0.3) ); | |
92 | data.insert( bm_type::value_type(4,0.4) ); | |
93 | ||
94 | bm_type bm; | |
95 | ||
96 | test_multiset_multiset_bimap(bm,data,left_data,right_data); | |
97 | test_tagged_bimap<left_tag,right_tag>(bm,data); | |
98 | } | |
99 | //-------------------------------------------------------------------- | |
100 | ||
101 | ||
102 | //-------------------------------------------------------------------- | |
103 | { | |
104 | typedef bimap<int,double,right_based> bm_type; | |
105 | ||
106 | std::set< bm_type::value_type > data; | |
107 | data.insert( bm_type::value_type(1,0.1) ); | |
108 | data.insert( bm_type::value_type(2,0.2) ); | |
109 | data.insert( bm_type::value_type(3,0.3) ); | |
110 | data.insert( bm_type::value_type(4,0.4) ); | |
111 | ||
112 | bm_type bm; | |
113 | ||
114 | test_set_set_bimap(bm,data,left_data,right_data); | |
115 | } | |
116 | //-------------------------------------------------------------------- | |
117 | ||
118 | ||
119 | //-------------------------------------------------------------------- | |
120 | { | |
121 | typedef bimap | |
122 | < | |
123 | multiset_of< int, std::greater<int> >, set_of<std::string> , | |
124 | multiset_of_relation< std::greater< _relation > > | |
125 | ||
126 | > bimap_type; | |
127 | ||
128 | bimap_type b1; | |
129 | ||
130 | b1.insert( bimap_type::value_type(1,"one") ); | |
131 | ||
132 | bimap_type b2( b1 ); | |
133 | ||
134 | BOOST_CHECK( b1 == b2 ); | |
135 | BOOST_CHECK( ! ( b1 != b2 ) ); | |
136 | BOOST_CHECK( b1 <= b2 ); | |
137 | BOOST_CHECK( b1 >= b2 ); | |
138 | BOOST_CHECK( ! ( b1 < b2 ) ); | |
139 | BOOST_CHECK( ! ( b1 > b2 ) ); | |
140 | ||
141 | b1.insert( bimap_type::value_type(2,"two") ); | |
142 | ||
143 | b2 = b1; | |
144 | BOOST_CHECK( b2 == b1 ); | |
145 | ||
146 | b1.insert( bimap_type::value_type(3,"three") ); | |
147 | ||
148 | b2.left = b1.left; | |
149 | BOOST_CHECK( b2 == b1 ); | |
150 | ||
151 | b1.insert( bimap_type::value_type(4,"four") ); | |
152 | ||
153 | b2.right = b1.right; | |
154 | BOOST_CHECK( b2 == b1 ); | |
155 | ||
156 | b1.clear(); | |
157 | b2.swap(b1); | |
158 | BOOST_CHECK( b2.empty() && !b1.empty() ); | |
159 | ||
160 | b1.left.swap( b2.left ); | |
161 | BOOST_CHECK( b1.empty() && !b2.empty() ); | |
162 | ||
163 | b1.right.swap( b2.right ); | |
164 | BOOST_CHECK( b2.empty() && !b1.empty() ); | |
165 | } | |
166 | //-------------------------------------------------------------------- | |
167 | ||
168 | } | |
169 | ||
170 | ||
171 | int test_main( int, char* [] ) | |
172 | { | |
173 | test_bimap(); | |
174 | return 0; | |
175 | } | |
176 |