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 // Boost.Test
21 #include <boost/test/minimal.hpp>
22 
23 #include <boost/config.hpp>
24 
25 #include <string>
26 
27 #include <boost/bimap/bimap.hpp>
28 #include <boost/bimap/unordered_set_of.hpp>
29 
30 
test_bimap_info()31 int test_bimap_info()
32 {
33     using namespace boost::bimaps;
34 
35     typedef bimap< double, unordered_set_of<int>, with_info<std::string> > bm_type;
36 
37     bm_type bm;
38     const bm_type & cbm = bm;
39 
40     // Insertion with info
41     bm      .insert( bm_type::      value_type(1.1 ,   1, "one"   ) );
42     bm.left .insert( bm_type:: left_value_type(2.2 ,   2, "two"   ) );
43     bm.right.insert( bm_type::right_value_type(  3 , 3.3, "three" ) );
44 
45     bm.begin()->info = "1";
46     BOOST_CHECK( bm.right.find(1)->info == "1" );
47 
48     bm.left.find(2.2)->info = "2";
49     BOOST_CHECK( bm.right.find(2)->info == "2" );
50 
51     bm.right.find(3)->info = "3";
52     BOOST_CHECK( bm.right.find(3)->info == "3" );
53 
54     // Empty info insert
55     bm      .insert( bm_type::      value_type(4.4 ,   4) );
56     bm. left.insert( bm_type:: left_value_type(5.5 ,   5) );
57     bm.right.insert( bm_type::right_value_type(  6 , 6.6) );
58 
59     BOOST_CHECK( bm.right.find(4)->info == "" );
60 
61     bm.left.info_at(4.4) = "4";
62     BOOST_CHECK(  bm.right.info_at(4) == "4" );
63     BOOST_CHECK( cbm.right.info_at(4) == "4" );
64 
65     bm.right.info_at(5) = "5";
66     BOOST_CHECK(  bm.left.info_at(5.5) == "5" );
67     BOOST_CHECK( cbm.left.info_at(5.5) == "5" );
68 
69     return 0;
70 }
71 
72 
73 struct left  {};
74 struct right {};
75 struct info  {};
76 
test_tagged_bimap_info()77 int test_tagged_bimap_info()
78 {
79     using namespace boost::bimaps;
80 
81     typedef bimap< tagged<int,left>,
82                    tagged<int,right>,
83                    with_info<tagged<int,info> > > bm_type;
84 
85     bm_type bm;
86     const bm_type & cbm = bm;
87 
88     bm      .insert( bm_type::      value_type(1,1,1) );
89     bm.left .insert( bm_type:: left_value_type(2,2,2) );
90     bm.right.insert( bm_type::right_value_type(3,3,3) );
91 
92     bm.begin()->get<info>() = 10;
93     BOOST_CHECK( bm.right.find(1)->get<info>() == 10 );
94     BOOST_CHECK( cbm.right.find(1)->get<info>() == 10 );
95 
96     bm.left.find(2)->get<info>() = 20;
97     BOOST_CHECK( bm.right.find(2)->get<info>() == 20 );
98     BOOST_CHECK( cbm.right.find(2)->get<info>() == 20 );
99 
100     bm.right.find(3)->get<info>() = 30;
101     BOOST_CHECK( bm.right.find(3)->get<info>() == 30 );
102     BOOST_CHECK( cbm.right.find(3)->get<info>() == 30 );
103 
104     // Empty info insert
105     bm      .insert( bm_type::      value_type(4,4) );
106     bm. left.insert( bm_type:: left_value_type(5,5) );
107     bm.right.insert( bm_type::right_value_type(6,6) );
108 
109     bm.left.info_at(4) = 4;
110     BOOST_CHECK(  bm.right.info_at(4) == 4 );
111     BOOST_CHECK( cbm.right.info_at(4) == 4 );
112 
113     bm.right.info_at(5) = 5;
114     BOOST_CHECK(  bm.left.info_at(5) == 5 );
115     BOOST_CHECK( cbm.left.info_at(5) == 5 );
116 
117     return 0;
118 }
119 
test_main(int,char * [])120 int test_main( int, char* [] )
121 {
122     test_bimap_info();
123     test_tagged_bimap_info();
124     return 0;
125 }
126 
127