3 // Copyright (c) 2006-2007 Matias Capeletto
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)
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
18 #include <boost/config.hpp>
20 #define BOOST_BIMAP_DISABLE_SERIALIZATION
23 #include <boost/test/minimal.hpp>
33 // Set type specifications
34 #include <boost/bimap/list_of.hpp>
35 #include <boost/bimap/vector_of.hpp>
38 #include <boost/bimap/bimap.hpp>
39 #include <boost/bimap/support/lambda.hpp>
41 #include <libs/bimap/test/test_bimap.hpp>
47 template< class Container, class Data >
48 void test_list_operations(Container & b, Container& c, const Data & d)
51 c.assign(d.begin(),d.end());
53 BOOST_CHECK( std::equal( c.begin(), c.end(), d.begin() ) );
55 BOOST_CHECK( std::equal( c.begin(), c.end(), d.rbegin() ) );
58 BOOST_CHECK( std::equal( c.begin(), c.end(), d.begin() ) );
60 c.push_front( *d.begin() );
61 BOOST_CHECK( c.size() == d.size()+1 );
63 BOOST_CHECK( c.size() == d.size() );
65 c.relocate( c.begin(), ++c.begin() );
66 c.relocate( c.end(), c.begin(), ++c.begin() );
71 c.assign(d.begin(),d.end());
72 b.splice(b.begin(),c);
74 BOOST_CHECK( c.size() == 0 );
75 BOOST_CHECK( b.size() == d.size() );
77 c.splice(c.begin(),b,++b.begin());
79 BOOST_CHECK( c.size() == 1 );
81 c.splice(c.begin(),b,b.begin(),b.end());
83 BOOST_CHECK( b.size() == 0 );
85 b.assign(d.begin(),d.end());
86 c.assign(d.begin(),d.end());
90 BOOST_CHECK( b.size() == 2*d.size() );
97 using namespace boost::bimaps;
99 typedef std::map<std::string,long> left_data_type;
100 left_data_type left_data;
101 left_data.insert( left_data_type::value_type("1",1) );
102 left_data.insert( left_data_type::value_type("2",2) );
103 left_data.insert( left_data_type::value_type("3",3) );
104 left_data.insert( left_data_type::value_type("4",4) );
106 typedef std::map<long,std::string> right_data_type;
107 right_data_type right_data;
108 right_data.insert( right_data_type::value_type(1,"1") );
109 right_data.insert( right_data_type::value_type(2,"2") );
110 right_data.insert( right_data_type::value_type(3,"3") );
111 right_data.insert( right_data_type::value_type(4,"4") );
114 //--------------------------------------------------------------------
117 list_of< std::string >, vector_of< long >
121 std::set< bm_type::value_type > data;
122 data.insert( bm_type::value_type("1",1) );
123 data.insert( bm_type::value_type("2",2) );
124 data.insert( bm_type::value_type("3",3) );
125 data.insert( bm_type::value_type("4",4) );
129 test_bimap_init_copy_swap<bm_type>(data) ;
130 test_sequence_container(b,data);
131 test_sequence_container(b.left , left_data);
132 test_vector_container(b.right,right_data);
134 test_mapped_container(b.left );
135 test_mapped_container(b.right);
138 test_list_operations(b,c,data) ;
139 test_list_operations(b.left,c.left,left_data) ;
140 test_list_operations(b.right,c.right,right_data) ;
142 c.assign(data.begin(),data.end());
143 b.assign(data.begin(),data.end());
144 c.remove_if(_key<=bm_type::value_type("1",1));
145 c.sort(std::less<bm_type::value_type>());
146 b.sort(std::less<bm_type::value_type>());
147 c.merge(b,std::less<bm_type::value_type>());
148 c.unique(std::equal_to<bm_type::value_type>());
150 c.assign(data.begin(),data.end());
151 b.assign(data.begin(),data.end());
152 c.left.remove_if(_key<="1");
153 c.left.sort(std::less<std::string>());
154 b.left.sort(std::less<std::string>());
155 c.left.merge(b.left,std::less<std::string>());
156 c.left.unique(std::equal_to<std::string>());
158 c.assign(data.begin(),data.end());
159 b.assign(data.begin(),data.end());
160 c.right.remove_if(_key<=1);
161 c.right.sort(std::less<long>());
162 b.right.sort(std::less<long>());
163 c.right.merge(b.right,std::less<long>());
164 c.right.unique(std::equal_to<long>());
166 c.assign(data.begin(),data.end());
167 c.right[0].first = -1;
168 c.right.at(0).second = "[1]";
170 //--------------------------------------------------------------------
173 //--------------------------------------------------------------------
177 vector_of<std::string>, list_of<long>,
182 std::set< bm_type::value_type > data;
183 data.insert( bm_type::value_type("1",1) );
184 data.insert( bm_type::value_type("2",2) );
185 data.insert( bm_type::value_type("3",3) );
186 data.insert( bm_type::value_type("4",4) );
190 test_bimap_init_copy_swap<bm_type>(data) ;
191 test_vector_container(b,data) ;
194 test_list_operations(b,c,data) ;
195 test_list_operations(b.left,c.left,left_data) ;
196 test_list_operations(b.right,c.right,right_data) ;
198 c.assign(data.begin(),data.end());
199 b.assign(data.begin(),data.end());
200 c.remove_if(_key<=bm_type::value_type("1",1));
201 c.sort(std::less<bm_type::value_type>());
202 b.sort(std::less<bm_type::value_type>());
203 c.merge(b,std::less<bm_type::value_type>());
204 c.unique(std::equal_to<bm_type::value_type>());
206 c.assign(data.begin(),data.end());
207 b.assign(data.begin(),data.end());
208 c.left.remove_if(_key<="1");
209 c.left.sort(std::less<std::string>());
210 b.left.sort(std::less<std::string>());
211 c.left.merge(b.left,std::less<std::string>());
212 c.left.unique(std::equal_to<std::string>());
214 c.assign(data.begin(),data.end());
215 b.assign(data.begin(),data.end());
216 c.right.remove_if(_key<=1);
217 c.right.sort(std::less<long>());
218 b.right.sort(std::less<long>());
219 c.right.merge(b.right,std::less<long>());
220 c.right.unique(std::equal_to<long>());
222 c.assign(data.begin(),data.end());
225 c.left[0].first = "[1]";
226 c.left.at(0).second = -1;
228 //--------------------------------------------------------------------
231 //--------------------------------------------------------------------
235 vector_of<std::string>, list_of<long>,
240 std::set< bm_type::value_type > data;
241 data.insert( bm_type::value_type("1",1) );
242 data.insert( bm_type::value_type("2",2) );
243 data.insert( bm_type::value_type("3",3) );
244 data.insert( bm_type::value_type("4",4) );
248 test_bimap_init_copy_swap<bm_type>(data) ;
249 test_sequence_container(b,data) ;
252 test_list_operations(b,c,data) ;
253 test_list_operations(b.left,c.left,left_data) ;
254 test_list_operations(b.right,c.right,right_data) ;
257 c.assign(data.begin(),data.end());
258 b.assign(data.begin(),data.end());
259 c.remove_if(_key<=bm_type::value_type("1",1));
260 c.sort(std::less<bm_type::value_type>());
261 b.sort(std::less<bm_type::value_type>());
262 c.merge(b,std::less<bm_type::value_type>());
263 c.unique(std::equal_to<bm_type::value_type>());
265 c.assign(data.begin(),data.end());
266 c.left[0].first = "[1]";
267 c.left.at(0).second = -1;
269 //--------------------------------------------------------------------
274 int test_main( int, char* [] )