]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/range/test/algorithm_test/remove_if.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/remove_if.hpp>
13 #include <boost/test/test_tools.hpp>
14 #include <boost/test/unit_test.hpp>
16 #include <boost/assign.hpp>
17 #include <boost/bind/bind.hpp>
29 template< class Container
, class UnaryPredicate
>
30 void test_remove_if_impl( const Container
& c
, UnaryPredicate pred
)
32 Container
reference(c
);
34 typedef BOOST_DEDUCED_TYPENAME
Container::iterator iterator_t
;
36 iterator_t reference_it
37 = std::remove_if(reference
.begin(), reference
.end(), pred
);
40 iterator_t test_it
= boost::remove_if(test
, pred
);
42 BOOST_CHECK_EQUAL( std::distance(test
.begin(), test_it
),
43 std::distance(reference
.begin(), reference_it
) );
45 BOOST_CHECK_EQUAL_COLLECTIONS( reference
.begin(), reference
.end(),
46 test
.begin(), test
.end() );
49 iterator_t test_it2
= boost::remove_if(
50 boost::make_iterator_range(test2
), pred
);
52 BOOST_CHECK_EQUAL( std::distance(test2
.begin(), test_it2
),
53 std::distance(reference
.begin(), reference_it
) );
55 BOOST_CHECK_EQUAL_COLLECTIONS( reference
.begin(), reference
.end(),
56 test2
.begin(), test2
.end() );
59 template< class Container
>
60 void test_remove_if_( const Container
& c
, int to_remove
)
62 using namespace boost::placeholders
;
64 test_remove_if_impl(c
, boost::bind(std::equal_to
<int>(), _1
, to_remove
));
65 test_remove_if_impl(c
, boost::bind(std::not_equal_to
<int>(), _1
, to_remove
));
68 template< class Container
>
69 void test_remove_if_impl()
71 using namespace boost::assign
;
74 test_remove_if_(cont
, 0);
78 test_remove_if_(cont
, 0);
79 test_remove_if_(cont
, 1);
83 test_remove_if_(cont
, 0);
84 test_remove_if_(cont
, 1);
87 cont
+= 1,2,3,4,5,6,7,8,9;
88 test_remove_if_(cont
, 1);
89 test_remove_if_(cont
, 9);
90 test_remove_if_(cont
, 4);
93 inline void test_remove_if()
95 test_remove_if_impl
< std::vector
<int> >();
96 test_remove_if_impl
< std::list
<int> >();
97 test_remove_if_impl
< std::deque
<int> >();
102 boost::unit_test::test_suite
*
103 init_unit_test_suite(int argc
, char* argv
[])
105 boost::unit_test::test_suite
* test
106 = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.remove_if" );
108 test
->add( BOOST_TEST_CASE( &boost::test_remove_if
) );