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 #include <boost/bimap/bimap.hpp>
27 #include <boost/bimap/multiset_of.hpp>
29 using namespace boost::bimaps
;
31 void untagged_version()
33 //[ code_user_defined_names_untagged_version
37 multiset_of
<std::string
>,
49 // people.right : map<id,name>
51 People::right_const_iterator id_iter
= people
.right
.find(user_id
);
52 if( id_iter
!= people
.right
.end() )
57 std::cout
<< "name: " << id_iter
->second
<< std::endl
58 << "id: " << id_iter
->first
<< std::endl
;
62 std::cout
<< "Unknown id, users are:" << std::endl
;
64 // people.left : map<name,id>
66 for( People::left_const_iterator
67 name_iter
= people
.left
.begin(),
68 iend
= people
.left
.end();
70 name_iter
!= iend
; ++name_iter
)
75 std::cout
<< "name: " << name_iter
->first
<< std::endl
76 << "id: " << name_iter
->second
<< std::endl
;
87 //[ code_user_defined_names_tagged_version
92 struct id {}; // Tag for the identification number
93 struct name {}; // Tag for the name of the person
101 multiset_of
< tagged
< std::string
, name
> >
112 People::map_by
<id
>::const_iterator id_iter
= people
.by
<id
>().find(user_id
);
113 if( id_iter
!= people
.by
<id
>().end() )
115 std::cout
<< "name: " << id_iter
->get
<name
>() << std::endl
116 << "id: " << id_iter
->get
<id
>() << std::endl
;
120 std::cout
<< "Unknown id, users are:" << std::endl
;
122 for( People::map_by
<name
>::const_iterator
123 name_iter
= people
.by
<name
>().begin(),
124 iend
= people
.by
<name
>().end();
126 name_iter
!= iend
; ++name_iter
)
128 std::cout
<< "name: " << name_iter
->get
<name
>() << std::endl
129 << "id: " << name_iter
->get
<id
>() << std::endl
;