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