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