]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/range/test/algorithm_test/for_each.cpp
3 // Copyright Neil Groves 2009. Use, modification and
4 // distribution is subject to the Boost Software License, Version
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
9 // For more information, see http://www.boost.org/libs/range/
11 #include <boost/range/algorithm/for_each.hpp>
13 #include <boost/test/test_tools.hpp>
14 #include <boost/test/unit_test.hpp>
16 #include <boost/array.hpp>
17 #include <boost/assign.hpp>
18 #include <boost/range/algorithm.hpp>
23 #include "../test_function/check_equal_fn.hpp"
29 template< class Range
>
30 unsigned int udistance(Range
& rng
)
32 return static_cast<unsigned int>(boost::distance(rng
));
35 template< class SinglePassRange
>
36 void test_for_each_impl( SinglePassRange rng
)
38 using namespace boost::range_test_function
;
40 typedef check_equal_fn
< SinglePassRange
> fn_t
;
42 // Test the mutable version
43 fn_t result_fn
= boost::for_each(rng
, fn_t(rng
));
44 BOOST_CHECK_EQUAL( boost::udistance(rng
), result_fn
.invocation_count() );
46 fn_t result_fn2
= boost::for_each(boost::make_iterator_range(rng
), fn_t(rng
));
47 BOOST_CHECK_EQUAL( boost::udistance(rng
), result_fn2
.invocation_count() );
49 // Test the constant version
50 const SinglePassRange
& cref_rng
= rng
;
51 result_fn
= boost::for_each(cref_rng
, fn_t(cref_rng
));
52 BOOST_CHECK_EQUAL( boost::udistance(cref_rng
), result_fn
.invocation_count() );
55 template< class Container
>
56 void test_for_each_t()
58 using namespace boost::assign
;
62 test_for_each_impl(cont
);
66 test_for_each_impl(cont
);
69 cont
+= 1,2,3,4,5,6,7,8,9;
70 test_for_each_impl(cont
);
75 boost::array
<int, 10> a
= {{ 0,1,2,3,4,5,6,7,8,9 }};
76 test_for_each_impl(a
);
78 test_for_each_t
< std::vector
<int> >();
79 test_for_each_t
< std::list
<int> >();
80 test_for_each_t
< std::set
<int> >();
81 test_for_each_t
< std::multiset
<int> >();
86 boost::unit_test::test_suite
*
87 init_unit_test_suite(int argc
, char* argv
[])
89 boost::unit_test::test_suite
* test
90 = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.for_each" );
92 test
->add( BOOST_TEST_CASE( &boost::test_for_each
) );