]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/bimap/test/test_bimap_info.cpp
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 #include <boost/core/lightweight_test.hpp>
22 #include <boost/config.hpp>
26 #include <boost/bimap/bimap.hpp>
27 #include <boost/bimap/unordered_set_of.hpp>
32 using namespace boost::bimaps
;
34 typedef bimap
< double, unordered_set_of
<int>, with_info
<std::string
> > bm_type
;
37 const bm_type
& cbm
= bm
;
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" ) );
44 bm
.begin()->info
= "1";
45 BOOST_TEST( bm
.right
.find(1)->info
== "1" );
47 bm
.left
.find(2.2)->info
= "2";
48 BOOST_TEST( bm
.right
.find(2)->info
== "2" );
50 bm
.right
.find(3)->info
= "3";
51 BOOST_TEST( bm
.right
.find(3)->info
== "3" );
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) );
58 BOOST_TEST( bm
.right
.find(4)->info
== "" );
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" );
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" );
76 int test_tagged_bimap_info()
78 using namespace boost::bimaps
;
80 typedef bimap
< tagged
<int,left
>,
82 with_info
<tagged
<int,info
> > > bm_type
;
85 const bm_type
& cbm
= bm
;
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) );
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 );
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 );
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 );
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) );
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 );
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 );
122 test_tagged_bimap_info();
123 return boost::report_errors();