]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/range/test/algorithm_test/replace_copy.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / range / test / algorithm_test / replace_copy.cpp
1 // Boost.Range library
2 //
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)
7 //
8 //
9 // For more information, see http://www.boost.org/libs/range/
10 //
11 #include <boost/range/algorithm/replace_copy.hpp>
12
13 #include <boost/test/test_tools.hpp>
14 #include <boost/test/unit_test.hpp>
15
16 #include <boost/assign.hpp>
17 #include <boost/bind.hpp>
18 #include <algorithm>
19 #include <functional>
20 #include <list>
21 #include <numeric>
22 #include <deque>
23 #include <vector>
24
25 namespace
26 {
27 template<typename Iterator, typename Value>
28 void test_append(Iterator target, Value value)
29 {
30 *target++ = value;
31 }
32
33 template< class Container, class Value >
34 void test_replace_copy_impl( const Container& c, Value to_replace )
35 {
36 const Value replace_with = to_replace * 2;
37
38 typedef typename boost::range_value<Container>::type value_type;
39 std::vector<value_type> reference;
40
41 typedef BOOST_DEDUCED_TYPENAME std::vector<value_type>::iterator
42 iterator_t BOOST_RANGE_UNUSED;
43
44 test_append(
45 std::replace_copy(c.begin(), c.end(),
46 std::back_inserter(reference), to_replace, replace_with),
47 to_replace);
48
49 std::vector<value_type> test;
50 test_append(
51 boost::replace_copy(c, std::back_inserter(test), to_replace, replace_with),
52 to_replace);
53
54 BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
55 test.begin(), test.end() );
56
57 std::vector<value_type> test2;
58 test_append(
59 boost::replace_copy(boost::make_iterator_range(c),
60 std::back_inserter(test2), to_replace,
61 replace_with),
62 to_replace);
63
64 BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
65 test2.begin(), test2.end() );
66 }
67
68 template< class Container >
69 void test_replace_copy_impl()
70 {
71 using namespace boost::assign;
72
73 Container cont;
74 test_replace_copy_impl(cont, 0);
75
76 cont.clear();
77 cont += 1;
78 test_replace_copy_impl(cont, 0);
79 test_replace_copy_impl(cont, 1);
80
81 cont.clear();
82 cont += 1,1,1,1,1;
83 test_replace_copy_impl(cont, 0);
84 test_replace_copy_impl(cont, 1);
85
86 cont.clear();
87 cont += 1,2,3,4,5,6,7,8,9;
88 test_replace_copy_impl(cont, 1);
89 test_replace_copy_impl(cont, 9);
90 test_replace_copy_impl(cont, 4);
91 }
92
93 void test_replace_copy()
94 {
95 test_replace_copy_impl< std::vector<int> >();
96 test_replace_copy_impl< std::list<int> >();
97 test_replace_copy_impl< std::deque<int> >();
98 }
99 }
100
101 boost::unit_test::test_suite*
102 init_unit_test_suite(int argc, char* argv[])
103 {
104 boost::unit_test::test_suite* test
105 = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.replace_copy" );
106
107 test->add( BOOST_TEST_CASE( &test_replace_copy ) );
108
109 return test;
110 }
111