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 #include <boost/config.hpp>
21 #include <boost/test/minimal.hpp>
23 #include <boost/config.hpp>
27 #include <boost/range/functions.hpp>
28 #include <boost/range/metafunctions.hpp>
30 #include <boost/bimap/bimap.hpp>
31 #include <boost/bimap/multiset_of.hpp>
32 #include <boost/bimap/support/lambda.hpp>
35 template< class ForwardReadableRange
, class UnaryFunctor
>
36 UnaryFunctor
for_each(const ForwardReadableRange
& r
, UnaryFunctor func
)
39 boost::range_const_iterator
<ForwardReadableRange
>::type const_iterator
;
41 for(const_iterator i
= boost::begin(r
), iend
= boost::end(r
); i
!=iend
; ++i
)
49 struct do_something_with_a_pair
51 template< class Pair
>
52 void operator()(const Pair
& p
)
54 BOOST_CHECK( p
.first
&& p
.second
);
58 int test_bimap_range()
60 using namespace boost::bimaps
;
62 typedef bimap
< double, multiset_of
<int> > bm_type
;
66 bm
.insert( bm_type::value_type(1.1 , 1) );
67 bm
.insert( bm_type::value_type(2.2 , 2) );
68 bm
.insert( bm_type::value_type(3.3 , 3) );
69 bm
.insert( bm_type::value_type(4.4 , 4) );
72 for_each( bm
.left
.range( 1.0 < _key
, _key
< 5.0 ),
73 do_something_with_a_pair() );
75 for_each( bm
.right
.range( unbounded
, _key
<= 2 ),
76 do_something_with_a_pair() );
82 bm_type::left_range_type r
= bm
.left
.range( 2.0 < _key
, _key
< 4.0 );
83 BOOST_CHECK( ! boost::empty(r
) );
84 BOOST_CHECK( boost::begin(r
) == bm
.left
.upper_bound(2.0) );
85 BOOST_CHECK( boost::end(r
) == bm
.left
.lower_bound(4.0) );
92 bm_type::right_range_type r
= bm
.right
.range( 2 <= _key
, _key
<= 3 );
93 BOOST_CHECK( ! boost::empty(r
) );
94 BOOST_CHECK( boost::begin(r
) == bm
.right
.lower_bound(2) );
95 BOOST_CHECK( boost::end(r
) == bm
.right
.upper_bound(3) );
99 // const range from range
102 bm_type:: left_const_range_type lr
= bm
. left
.range( unbounded
, _key
< 4.0 );
103 bm_type::right_const_range_type rr
= bm
.right
.range( 2 < _key
, unbounded
);
107 const bm_type
& cbm
= bm
;
111 bm_type:: left_const_range_type r
= cbm
.left
.range( unbounded
, unbounded
);
112 BOOST_CHECK( ! boost::empty(r
) );
113 BOOST_CHECK( boost::begin(r
) == cbm
.left
.begin() );
120 bm_type::right_const_range_type r
= cbm
.right
.range( 1 < _key
, _key
< 1 );
121 BOOST_CHECK( boost::empty(r
) );
129 int test_main( int, char* [] )