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/unordered_set_of.hpp> |
33 | #include <boost/bimap/unordered_multiset_of.hpp> |
34 | |
35 | // bimap container |
36 | #include <boost/bimap/bimap.hpp> |
37 | |
38 | #include <libs/bimap/test/strong_type.hpp> |
39 | #include <libs/bimap/test/test_bimap.hpp> |
40 | |
41 | struct left_tag {}; |
42 | struct right_tag {}; |
43 | |
44 | void test_bimap() |
45 | { |
46 | using namespace boost::bimaps; |
47 | |
48 | |
49 | typedef std::map<char,std::string> left_data_type; |
50 | left_data_type left_data; |
51 | left_data.insert( x: left_data_type::value_type('a',"a" ) ); |
52 | left_data.insert( x: left_data_type::value_type('b',"b" ) ); |
53 | left_data.insert( x: left_data_type::value_type('c',"c" ) ); |
54 | left_data.insert( x: left_data_type::value_type('d',"e" ) ); |
55 | |
56 | typedef std::map<std::string,char> right_data_type; |
57 | right_data_type right_data; |
58 | right_data.insert( x: right_data_type::value_type("a" ,'a') ); |
59 | right_data.insert( x: right_data_type::value_type("b" ,'b') ); |
60 | right_data.insert( x: right_data_type::value_type("c" ,'c') ); |
61 | right_data.insert( x: right_data_type::value_type("d" ,'e') ); |
62 | |
63 | |
64 | |
65 | //-------------------------------------------------------------------- |
66 | { |
67 | typedef bimap< |
68 | unordered_set_of<char>, unordered_multiset_of<std::string> |
69 | |
70 | > bm_type; |
71 | |
72 | std::set< bm_type::value_type > data; |
73 | data.insert( x: bm_type::value_type('a',"a" ) ); |
74 | data.insert( x: bm_type::value_type('b',"b" ) ); |
75 | data.insert( x: bm_type::value_type('c',"c" ) ); |
76 | data.insert( x: bm_type::value_type('d',"d" ) ); |
77 | |
78 | bm_type bm; |
79 | |
80 | test_unordered_set_unordered_multiset_bimap( |
81 | bm,data,left_data,right_data |
82 | ); |
83 | } |
84 | //-------------------------------------------------------------------- |
85 | |
86 | |
87 | //-------------------------------------------------------------------- |
88 | { |
89 | typedef bimap< |
90 | unordered_set_of< tagged< char , left_tag > >, |
91 | unordered_multiset_of< tagged< std::string, right_tag > > |
92 | |
93 | > bm_type; |
94 | |
95 | std::set< bm_type::value_type > data; |
96 | data.insert( x: bm_type::value_type('a',"a" ) ); |
97 | data.insert( x: bm_type::value_type('b',"b" ) ); |
98 | data.insert( x: bm_type::value_type('c',"c" ) ); |
99 | data.insert( x: bm_type::value_type('d',"d" ) ); |
100 | |
101 | bm_type bm; |
102 | |
103 | test_unordered_set_unordered_multiset_bimap( |
104 | bm,data,left_data,right_data |
105 | ); |
106 | test_tagged_bimap<left_tag,right_tag>(bm,data); |
107 | } |
108 | //-------------------------------------------------------------------- |
109 | |
110 | |
111 | //-------------------------------------------------------------------- |
112 | { |
113 | typedef bimap |
114 | < |
115 | set_of< char, std::greater<char> >, |
116 | unordered_multiset_of<std::string>, |
117 | unordered_set_of_relation<> |
118 | |
119 | > bm_type; |
120 | |
121 | std::set< bm_type::value_type > data; |
122 | data.insert( x: bm_type::value_type('a',"a" ) ); |
123 | data.insert( x: bm_type::value_type('b',"b" ) ); |
124 | data.insert( x: bm_type::value_type('c',"c" ) ); |
125 | data.insert( x: bm_type::value_type('d',"d" ) ); |
126 | |
127 | bm_type bm; |
128 | |
129 | test_basic_bimap(bm,data,left_data,right_data); |
130 | test_associative_container(bm,data); |
131 | test_simple_unordered_associative_container(bm,data); |
132 | } |
133 | //-------------------------------------------------------------------- |
134 | |
135 | |
136 | //-------------------------------------------------------------------- |
137 | { |
138 | typedef bimap |
139 | < |
140 | unordered_multiset_of< char >, |
141 | unordered_multiset_of< std::string >, |
142 | unordered_multiset_of_relation<> |
143 | |
144 | > bm_type; |
145 | |
146 | std::set< bm_type::value_type > data; |
147 | data.insert( x: bm_type::value_type('a',"a" ) ); |
148 | data.insert( x: bm_type::value_type('b',"b" ) ); |
149 | data.insert( x: bm_type::value_type('c',"c" ) ); |
150 | data.insert( x: bm_type::value_type('d',"d" ) ); |
151 | |
152 | bm_type bm; |
153 | |
154 | test_basic_bimap(bm,data,left_data,right_data); |
155 | test_associative_container(bm,data); |
156 | test_simple_unordered_associative_container(bm,data); |
157 | |
158 | } |
159 | //-------------------------------------------------------------------- |
160 | { |
161 | typedef bimap |
162 | < |
163 | unordered_set_of |
164 | < |
165 | int, boost::hash< strong<int> >, std::equal_to< strong<int> > |
166 | >, |
167 | unordered_multiset_of< |
168 | int, boost::hash< strong<int> >, std::equal_to< strong<int> > |
169 | >, |
170 | unordered_set_of_relation<> |
171 | |
172 | > bm_type; |
173 | |
174 | std::set< bm_type::value_type > data; |
175 | data.insert( bm_type::value_type(1,1) ); |
176 | data.insert( bm_type::value_type(2,2) ); |
177 | data.insert( bm_type::value_type(3,3) ); |
178 | data.insert( bm_type::value_type(4,4) ); |
179 | |
180 | std::map<int,int> sided_data; |
181 | sided_data.emplace(args: 1,args: 1); |
182 | sided_data.emplace(args: 2,args: 2); |
183 | sided_data.emplace(args: 3,args: 3); |
184 | sided_data.emplace(args: 4,args: 4); |
185 | |
186 | bm_type bm; |
187 | |
188 | test_basic_bimap(bm,data,sided_data,sided_data); |
189 | test_associative_container(bm,data); |
190 | test_simple_unordered_associative_container(bm,data); |
191 | test_pair_heterogeneous_associative_container< strong<int> >( |
192 | bm.left,sided_data); |
193 | test_pair_heterogeneous_associative_container< strong<int> >( |
194 | bm.right,sided_data); |
195 | } |
196 | //-------------------------------------------------------------------- |
197 | } |
198 | |
199 | |
200 | int main() |
201 | { |
202 | test_bimap(); |
203 | return boost::report_errors(); |
204 | } |
205 | |
206 | |