]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/range/test/algorithm_test/stable_partition.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / range / test / algorithm_test / stable_partition.cpp
1 // Copyright Neil Groves 2009. Use, modification and
2 // distribution is subject to the Boost Software License, Version
3 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 //
6 //
7 // For more information, see http://www.boost.org/libs/range/
8 //
9 #include <boost/range/algorithm/stable_partition.hpp>
10
11 #include <boost/test/test_tools.hpp>
12 #include <boost/test/unit_test.hpp>
13
14 #include <boost/assign.hpp>
15 #include <boost/bind.hpp>
16 #include "../test_driver/range_return_test_driver.hpp"
17 #include <algorithm>
18 #include <functional>
19 #include <list>
20 #include <numeric>
21 #include <deque>
22 #include <vector>
23
24 namespace boost_range_test_algorithm_stable_partition
25 {
26 struct equal_to_5
27 {
28 typedef bool result_type;
29 typedef int argument_type;
30 bool operator()(int x) const { return x == 5; }
31 };
32
33 // test the 'partition' algorithm
34 template<class UnaryPredicate>
35 class stable_partition_test_policy
36 {
37 public:
38 template< class Container >
39 BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
40 test_iter(Container& cont)
41 {
42 Container cont2(cont);
43
44 typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type iter_t;
45 iter_t result = boost::stable_partition(cont, UnaryPredicate());
46
47 iter_t temp_result = boost::stable_partition(
48 boost::make_iterator_range(cont2), UnaryPredicate());
49
50 BOOST_CHECK_EQUAL( std::distance(cont.begin(), result),
51 std::distance(cont2.begin(), temp_result) );
52
53 BOOST_CHECK_EQUAL_COLLECTIONS( cont.begin(), cont.end(),
54 cont2.begin(), cont2.end() );
55
56 return result;
57 }
58
59 UnaryPredicate pred() const { return UnaryPredicate(); }
60
61 template< boost::range_return_value return_type >
62 struct test_range
63 {
64 template< class Container, class Policy >
65 BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type
66 operator()(Policy& policy, Container& cont)
67 {
68 typedef BOOST_DEDUCED_TYPENAME boost::range_return<Container,return_type>::type result_t;
69 Container cont2(cont);
70 result_t result = boost::stable_partition<return_type>(cont, policy.pred());
71
72 result_t result2 = boost::stable_partition<return_type>(
73 boost::make_iterator_range(cont2), policy.pred());
74
75 boost::ignore_unused_variable_warning(result2);
76
77 BOOST_CHECK_EQUAL_COLLECTIONS( cont2.begin(), cont2.end(),
78 cont.begin(), cont.end() );
79
80 return result;
81 }
82 };
83
84 template< class Container >
85 BOOST_DEDUCED_TYPENAME boost::range_iterator<Container>::type
86 reference(Container& cont)
87 {
88 return std::stable_partition(cont.begin(), cont.end(), UnaryPredicate());
89 }
90 };
91
92 template<class Container>
93 void test_stable_partition_impl()
94 {
95 using namespace boost::assign;
96
97 boost::range_test::range_return_test_driver test_driver;
98
99 stable_partition_test_policy< equal_to_5 > policy;
100
101 Container cont;
102 test_driver(cont, policy);
103
104 cont.clear();
105 cont += 1;
106 test_driver(cont, policy);
107
108 cont.clear();
109 cont += 1,2,2,2,2,2,3,4,5,6,7,8,9;
110 test_driver(cont, policy);
111
112 cont.clear();
113 cont += 1,2,2,2,2,2,3,3,3,3,4,4,4,4,4,4,4,5,6,7,8,9;
114 test_driver(cont, policy);
115 }
116
117 void test_stable_partition()
118 {
119 test_stable_partition_impl< std::vector<int> >();
120 test_stable_partition_impl< std::list<int> >();
121 test_stable_partition_impl< std::deque<int> >();
122 }
123 }
124
125 boost::unit_test::test_suite*
126 init_unit_test_suite(int argc, char* argv[])
127 {
128 boost::unit_test::test_suite* test
129 = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.stable_partition" );
130
131 test->add( BOOST_TEST_CASE( &boost_range_test_algorithm_stable_partition::test_stable_partition ) );
132
133 return test;
134 }