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>
25 #include <boost/range/functions.hpp>
26 #include <boost/range/metafunctions.hpp>
28 //[ code_bimap_and_boost_range_functions
30 template< class ForwardReadableRange, class UnaryFunctor >
31 UnaryFunctor for_each(const ForwardReadableRange & r, UnaryFunctor func)
34 boost::range_const_iterator<ForwardReadableRange>::type const_iterator;
36 for(const_iterator i= boost::begin(r), iend= boost::end(r); i!=iend; ++i )
44 template< class ForwardReadableRange, class Predicate >
45 typename boost::range_difference<ForwardReadableRange>::type
46 count_if(const ForwardReadableRange & r, Predicate pred)
49 boost::range_const_iterator<ForwardReadableRange>::type const_iterator;
51 typename boost::range_difference<ForwardReadableRange>::type c = 0;
53 for( const_iterator i = boost::begin(r), iend = boost::end(r); i != iend; ++i )
62 #include <boost/bimap/bimap.hpp>
63 #include <boost/bimap/multiset_of.hpp>
64 #include <boost/bimap/support/lambda.hpp>
65 #include <boost/bind.hpp>
67 using namespace boost::bimaps;
68 using namespace boost;
70 //[ code_bimap_and_boost_range
74 pair_printer(std::ostream & o) : os(o) {}
75 template< class Pair >
76 void operator()(const Pair & p)
78 os << "(" << p.first << "," << p.second << ")";
84 struct second_extractor
86 template< class Pair >
87 const typename Pair::second_type & operator()(const Pair & p)
95 typedef bimap< double, multiset_of<int> > bm_type;
98 bm.insert( bm_type::value_type(2.5 , 1) );
99 bm.insert( bm_type::value_type(3.1 , 2) );
101 bm.insert( bm_type::value_type(6.4 , 4) );
102 bm.insert( bm_type::value_type(1.7 , 2) );
104 // Print all the elements of the left map view
106 for_each( bm.left, pair_printer(std::cout) );
108 // Print a range of elements of the right map view
110 for_each( bm.right.range( 2 <= _key, _key < 6 ), pair_printer(std::cout) );
112 // Count the number of elements where the data is equal to 2 from a
113 // range of elements of the left map view
115 count_if( bm.left.range( 2.3 < _key, _key < 5.4 ),
116 bind<int>( second_extractor(), _1 ) == 2 );