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