1// Boost.Bimap
2//
3// Copyright (c) 2006-2007 Matias Capeletto
4// Copyright (c) 2024 Joaquin M Lopez Munoz
5//
6// Distributed under the Boost Software License, Version 1.0.
7// (See accompanying file LICENSE_1_0.txt or copy at
8// http://www.boost.org/LICENSE_1_0.txt)
9
10// VC++ 8.0 warns on usage of certain Standard Library and API functions that
11// can be cause buffer overruns or other possible security issues if misused.
12// See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx
13// But the wording of the warning is misleading and unsettling, there are no
14// portable alternative functions, and VC++ 8.0's own libraries use the
15// functions in question. So turn off the warnings.
16#define _CRT_SECURE_NO_DEPRECATE
17#define _SCL_SECURE_NO_DEPRECATE
18
19#include <boost/config.hpp>
20
21#define BOOST_BIMAP_DISABLE_SERIALIZATION
22
23#include <boost/core/lightweight_test.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// List type specification
36#include <boost/bimap/list_of.hpp>
37
38// bimap container
39#include <boost/bimap/bimap.hpp>
40
41#include <libs/bimap/test/strong_type.hpp>
42#include <libs/bimap/test/test_bimap.hpp>
43
44struct left_tag {};
45struct right_tag {};
46
47void test_bimap()
48{
49 using namespace boost::bimaps;
50
51 typedef std::map<int,double> left_data_type;
52 left_data_type left_data;
53 left_data.insert( x: left_data_type::value_type(1,0.1) );
54 left_data.insert( x: left_data_type::value_type(2,0.2) );
55 left_data.insert( x: left_data_type::value_type(3,0.3) );
56 left_data.insert( x: left_data_type::value_type(4,0.4) );
57
58 typedef std::map<double,int> right_data_type;
59 right_data_type right_data;
60 right_data.insert( x: right_data_type::value_type(0.1,1) );
61 right_data.insert( x: right_data_type::value_type(0.2,2) );
62 right_data.insert( x: right_data_type::value_type(0.3,3) );
63 right_data.insert( x: right_data_type::value_type(0.4,4) );
64
65
66 //--------------------------------------------------------------------
67 {
68 typedef bimap< int, double > bm_type;
69
70 std::set< bm_type::value_type > data;
71 data.insert( x: bm_type::value_type(1,0.1) );
72 data.insert( x: bm_type::value_type(2,0.2) );
73 data.insert( x: bm_type::value_type(3,0.3) );
74 data.insert( x: bm_type::value_type(4,0.4) );
75
76 bm_type bm;
77 test_set_set_bimap(bm,data,left_data,right_data);
78 }
79 //--------------------------------------------------------------------
80
81
82 //--------------------------------------------------------------------
83 {
84 typedef bimap
85 <
86 multiset_of< tagged<int, left_tag > >,
87 multiset_of< tagged<double, right_tag > >,
88 multiset_of_relation< std::less< _relation > >
89
90 > bm_type;
91
92 std::set< bm_type::value_type > data;
93 data.insert( x: bm_type::value_type(1,0.1) );
94 data.insert( x: bm_type::value_type(2,0.2) );
95 data.insert( x: bm_type::value_type(3,0.3) );
96 data.insert( x: bm_type::value_type(4,0.4) );
97
98 bm_type bm;
99
100 test_multiset_multiset_bimap(bm,data,left_data,right_data);
101 test_tagged_bimap<left_tag,right_tag>(bm,data);
102 }
103 //--------------------------------------------------------------------
104
105
106 //--------------------------------------------------------------------
107 {
108 typedef bimap<int,double,right_based> bm_type;
109
110 std::set< bm_type::value_type > data;
111 data.insert( x: bm_type::value_type(1,0.1) );
112 data.insert( x: bm_type::value_type(2,0.2) );
113 data.insert( x: bm_type::value_type(3,0.3) );
114 data.insert( x: bm_type::value_type(4,0.4) );
115
116 bm_type bm;
117
118 test_set_set_bimap(bm,data,left_data,right_data);
119 }
120 //--------------------------------------------------------------------
121
122
123 //--------------------------------------------------------------------
124 {
125 typedef bimap
126 <
127 multiset_of< int, std::greater<int> >, set_of<std::string> ,
128 multiset_of_relation< std::greater< _relation > >
129
130 > bimap_type;
131
132 bimap_type b1;
133
134 b1.insert( x: bimap_type::value_type(1,"one") );
135
136 bimap_type b2( b1 );
137
138 BOOST_TEST( b1 == b2 );
139 BOOST_TEST( ! ( b1 != b2 ) );
140 BOOST_TEST( b1 <= b2 );
141 BOOST_TEST( b1 >= b2 );
142 BOOST_TEST( ! ( b1 < b2 ) );
143 BOOST_TEST( ! ( b1 > b2 ) );
144
145 b1.insert( x: bimap_type::value_type(2,"two") );
146
147 b2 = b1;
148 BOOST_TEST( b2 == b1 );
149
150 b1.insert( x: bimap_type::value_type(3,"three") );
151
152 b2.left = b1.left;
153 BOOST_TEST( b2 == b1 );
154
155 b1.insert( x: bimap_type::value_type(4,"four") );
156
157 b2.right = b1.right;
158 BOOST_TEST( b2 == b1 );
159
160 b1.clear();
161 b2.swap(c&: b1);
162 BOOST_TEST( b2.empty() && !b1.empty() );
163
164 b1.left.swap( c&: b2.left );
165 BOOST_TEST( b1.empty() && !b2.empty() );
166
167 b1.right.swap( c&: b2.right );
168 BOOST_TEST( b2.empty() && !b1.empty() );
169 }
170 //--------------------------------------------------------------------
171
172 {
173 typedef bimap
174 <
175 set_of< int, std::less< strong<int> > >,
176 multiset_of< int, std::less< strong<int> > >,
177 set_of_relation<>
178
179 > bm_type;
180
181 std::set< bm_type::value_type > data;
182 data.insert( bm_type::value_type(1,1) );
183 data.insert( bm_type::value_type(2,2) );
184 data.insert( bm_type::value_type(3,3) );
185 data.insert( bm_type::value_type(4,4) );
186
187 std::map<int,int> sided_data;
188 sided_data.emplace(args: 1,args: 1);
189 sided_data.emplace(args: 2,args: 2);
190 sided_data.emplace(args: 3,args: 3);
191 sided_data.emplace(args: 4,args: 4);
192
193 bm_type bm;
194
195 test_basic_bimap(bm,data,sided_data,sided_data);
196 test_associative_container(bm,data);
197 test_pair_heterogeneous_ordered_associative_container< strong<int> >(
198 bm.left,sided_data);
199 test_pair_heterogeneous_ordered_associative_container< strong<int> >(
200 bm.right,sided_data);
201 }
202 //--------------------------------------------------------------------
203}
204
205
206int main()
207{
208 test_bimap();
209 return boost::report_errors();
210}
211
212

source code of boost/libs/bimap/test/test_bimap_ordered.cpp