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 // Boost.Bimap Example
19 //-----------------------------------------------------------------------------
21 #include <boost/config.hpp>
26 // A convenience header is available in the boost directory:
27 #include <boost/bimap.hpp>
31 //[ code_step_by_step_definition
33 typedef boost::bimap
< int, std::string
> bm_type
;
37 //[ code_step_by_step_set_of_relations_view
39 bm
.insert( bm_type::value_type(1, "one" ) );
40 bm
.insert( bm_type::value_type(2, "two" ) );
42 std::cout
<< "There are " << bm
.size() << "relations" << std::endl
;
44 for( bm_type::const_iterator iter
= bm
.begin(), iend
= bm
.end();
45 iter
!= iend
; ++iter
)
47 // iter->left : data : int
48 // iter->right : data : std::string
50 std::cout
<< iter
->left
<< " <--> " << iter
->right
<< std::endl
;
54 //[ code_step_by_step_left_map_view
56 /*<< The type of `bm.left` is `bm_type::left_map` and the type
57 of `bm.right` is `bm_type::right_map` >>*/
58 typedef bm_type::left_map::const_iterator left_const_iterator
;
60 for( left_const_iterator left_iter
= bm
.left
.begin(), iend
= bm
.left
.end();
61 left_iter
!= iend
; ++left_iter
)
63 // left_iter->first : key : int
64 // left_iter->second : data : std::string
66 std::cout
<< left_iter
->first
<< " --> " << left_iter
->second
<< std::endl
;
69 /*<< `bm_type::left_`\ -type- can be used as a shortcut for the more verbose
70 `bm_type::left_map::`\ -type- >>*/
71 bm_type::left_const_iterator left_iter
= bm
.left
.find(2);
72 assert( left_iter
->second
== "two" );
74 /*<< This line produces the same effect of
75 `bm.insert( bm_type::value_type(3,"three") );` >>*/
76 bm
.left
.insert( bm_type::left_value_type( 3, "three" ) );
81 //[ code_step_by_step_right_map_view
83 bm_type::right_const_iterator right_iter
= bm
.right
.find("two");
85 // right_iter->first : key : std::string
86 // right_iter->second : data : int
88 assert( right_iter
->second
== 2 );
90 assert( bm
.right
.at("one") == 1 );
92 bm
.right
.erase("two");
94 /*<< This line produces the same effect of
95 `bm.insert( bm_type::value_type(4,"four") );` >>*/
96 bm
.right
.insert( bm_type::right_value_type( "four", 4 ) );