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>
26 #include <boost/foreach.hpp>
28 #include <boost/bimap/bimap.hpp>
29 #include <boost/bimap/list_of.hpp>
30 #include <boost/bimap/support/lambda.hpp>
32 using namespace boost::bimaps;
37 //[ code_bimap_and_boost_foreach
39 typedef bimap< std::string, list_of<int> > bm_type;
42 bm.insert( bm_type::value_type("1", 1) );
43 bm.insert( bm_type::value_type("2", 2) );
44 bm.insert( bm_type::value_type("3", 4) );
45 bm.insert( bm_type::value_type("4", 2) );
47 BOOST_FOREACH( bm_type::left_reference p, bm.left )
49 ++p.second; /*< We can modify the right element because we have
50 use a mutable collection type in the right side. >*/
53 BOOST_FOREACH( bm_type::right_const_reference p, bm.right )
55 std::cout << p.first << "-->" << p.second << std::endl;
62 BOOST_FOREACH( bm_type::right_reference p, bm.right )
67 BOOST_FOREACH( bm_type::left_const_reference p, bm.left )
69 std::cout << p.first << "-->" << p.second << std::endl;
72 BOOST_FOREACH( bm_type::reference p, bm )
77 const bm_type & cbm = bm;
78 BOOST_FOREACH( bm_type::const_reference p, cbm )
80 std::cout << p.left << "-->" << p.right << std::endl;
83 BOOST_FOREACH( bm_type::const_reference p, bm )
85 std::cout << p.left << "-->" << p.right << std::endl;
88 //[ code_bimap_and_boost_foreach_using_range
90 BOOST_FOREACH( bm_type::left_reference p,
91 ( bm.left.range( std::string("1") <= _key, _key < std::string("3") ) ))
96 BOOST_FOREACH( bm_type::left_const_reference p,
97 ( bm.left.range( std::string("1") <= _key, _key < std::string("3") ) ))
99 std::cout << p.first << "-->" << p.second << std::endl;