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#include <boost/core/lightweight_test.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#include <libs/bimap/test/strong_type.hpp>
31
32int test_bimap_info()
33{
34 using namespace boost::bimaps;
35
36 typedef bimap< double, unordered_set_of<int>, with_info<std::string> > bm_type;
37
38 bm_type bm;
39 const bm_type & cbm = bm;
40
41 // Insertion with info
42 bm .insert( bm_type:: value_type(1.1 , 1, "one" ) );
43 bm.left .insert( bm_type:: left_value_type(2.2 , 2, "two" ) );
44 bm.right.insert( bm_type::right_value_type( 3 , 3.3, "three" ) );
45
46 bm.begin()->info = "1";
47 BOOST_TEST( bm.right.find(1)->info == "1" );
48
49 bm.left.find(2.2)->info = "2";
50 BOOST_TEST( bm.right.find(2)->info == "2" );
51
52 bm.right.find(3)->info = "3";
53 BOOST_TEST( bm.right.find(3)->info == "3" );
54
55 // Empty info insert
56 bm .insert( bm_type:: value_type(4.4 , 4) );
57 bm. left.insert( bm_type:: left_value_type(5.5 , 5) );
58 bm.right.insert( bm_type::right_value_type( 6 , 6.6) );
59
60 BOOST_TEST( bm.right.find(4)->info == "" );
61
62 bm.left.info_at(4.4) = "4";
63 BOOST_TEST( bm.right.info_at(4) == "4" );
64 BOOST_TEST( cbm.right.info_at(4) == "4" );
65
66 bm.right.info_at(5) = "5";
67 BOOST_TEST( bm.left.info_at(5.5) == "5" );
68 BOOST_TEST( cbm.left.info_at(5.5) == "5" );
69
70 return 0;
71}
72
73
74struct left {};
75struct right {};
76struct info {};
77
78int test_tagged_bimap_info()
79{
80 using namespace boost::bimaps;
81
82 typedef bimap< tagged<int,left>,
83 tagged<int,right>,
84 with_info<tagged<int,info> > > bm_type;
85
86 bm_type bm;
87 const bm_type & cbm = bm;
88
89 bm .insert( x: bm_type:: value_type(1,1,1) );
90 bm.left .insert( x: bm_type:: left_value_type(2,2,2) );
91 bm.right.insert( x: bm_type::right_value_type(3,3,3) );
92
93 bm.begin()->get<info>() = 10;
94 BOOST_TEST( bm.right.find(1)->get<info>() == 10 );
95 BOOST_TEST( cbm.right.find(1)->get<info>() == 10 );
96
97 bm.left.find(k: 2)->get<info>() = 20;
98 BOOST_TEST( bm.right.find(2)->get<info>() == 20 );
99 BOOST_TEST( cbm.right.find(2)->get<info>() == 20 );
100
101 bm.right.find(k: 3)->get<info>() = 30;
102 BOOST_TEST( bm.right.find(3)->get<info>() == 30 );
103 BOOST_TEST( cbm.right.find(3)->get<info>() == 30 );
104
105 // Empty info insert
106 bm .insert( x: bm_type:: value_type(4,4) );
107 bm. left.insert( x: bm_type:: left_value_type(5,5) );
108 bm.right.insert( x: bm_type::right_value_type(6,6) );
109
110 bm.left.info_at(k: 4) = 4;
111 BOOST_TEST( bm.right.info_at(4) == 4 );
112 BOOST_TEST( cbm.right.info_at(4) == 4 );
113
114 bm.right.info_at(k: 5) = 5;
115 BOOST_TEST( bm.left.info_at(5) == 5 );
116 BOOST_TEST( cbm.left.info_at(5) == 5 );
117
118 return 0;
119}
120
121void test_heterogeneous_access_bimap_info()
122{
123 using namespace boost::bimaps;
124
125 typedef bimap
126 <
127 set_of< int, std::less< strong<int> > >,
128 unordered_set_of
129 <
130 int, boost::hash< strong<int> >, std::equal_to< strong<int> >
131 >,
132 with_info<int>
133 > bm_type;
134
135 bm_type bm;
136 bm.insert(bm_type::value_type(1,1,0));
137
138 BOOST_TEST( bm.left.info_at(strong<int>(1)) == 0 );
139 BOOST_TEST( bm.right.info_at(strong<int>(1)) == 0 );
140
141 bm.left.info_at(strong<int>(1))=1;
142 BOOST_TEST( bm.left.info_at(strong<int>(1)) == 1 );
143 BOOST_TEST( bm.right.info_at(strong<int>(1)) == 1 );
144
145 bm.right.info_at(strong<int>(1))=2;
146 BOOST_TEST( bm.left.info_at(strong<int>(1)) == 2 );
147 BOOST_TEST( bm.right.info_at(strong<int>(1)) == 2 );
148}
149
150int main()
151{
152 test_bimap_info();
153 test_tagged_bimap_info();
154 test_heterogeneous_access_bimap_info();
155 return boost::report_errors();
156}
157
158

source code of boost/libs/bimap/test/test_bimap_info.cpp