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 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>
28 #include <boost/bimap.hpp>
30 template< class MapType
>
31 void print_map(const MapType
& map
,
32 const std::string
& separator
,
35 typedef typename
MapType::const_iterator const_iterator
;
37 for( const_iterator i
= map
.begin(), iend
= map
.end(); i
!= iend
; ++i
)
39 os
<< i
->first
<< separator
<< i
->second
<< std::endl
;
47 typedef boost::bimap
< std::string
, int > results_bimap
;
48 typedef results_bimap::value_type position
;
50 results_bimap results
;
51 results
.insert( position("Argentina" ,1) );
52 results
.insert( position("Spain" ,2) );
53 results
.insert( position("Germany" ,3) );
54 results
.insert( position("France" ,4) );
56 std::cout
<< "The number of countries is " << results
.size()
59 std::cout
<< "The winner is " << results
.right
.at(1)
63 std::cout
<< "Countries names ordered by their final position:"
66 // results.right works like a std::map< int, std::string >
68 print_map( results
.right
, ") ", std::cout
);
70 std::cout
<< std::endl
71 << "Countries names ordered alphabetically along with"
72 "their final position:"
75 // results.left works like a std::map< std::string, int >
77 print_map( results
.left
, " ends in position ", std::cout
);