]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/range/test/algorithm_ext_test/push_front.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / range / test / algorithm_ext_test / push_front.cpp
1 // Boost.Range library
2 //
3 // Copyright Neil Groves 2010. 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_ext/push_front.hpp>
12
13 #include <boost/test/test_tools.hpp>
14 #include <boost/test/unit_test.hpp>
15
16 #include <boost/range/iterator.hpp>
17 #include <boost/range/irange.hpp>
18 #include <algorithm>
19 #include <list>
20 #include <vector>
21
22 namespace
23 {
24 struct DoubleValue
25 {
26 template< class Value >
27 Value operator()(Value x)
28 {
29 return x * 2;
30 }
31 };
32
33 template< class Container >
34 void test_push_front_impl(std::size_t n)
35 {
36 Container reference;
37 for (std::size_t i = 0; i < n; ++i)
38 reference.push_back(i);
39
40 Container test;
41 boost::push_front(test, boost::irange<std::size_t>(0, n));
42
43 BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
44 test.begin(), test.end() );
45
46 // copy the original reference sequence
47 Container reference_copy(reference);
48 std::transform(reference.begin(), reference.end(), reference.begin(), DoubleValue());
49
50 // Do it again to push onto non-empty container
51 reference.insert(reference.end(), reference_copy.begin(), reference_copy.end());
52
53 boost::push_front(test, boost::irange<std::size_t>(0, n * 2, 2));
54
55 BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
56 test.begin(), test.end() );
57 }
58
59 template< class Container >
60 void test_push_front_impl()
61 {
62 test_push_front_impl< Container >(0);
63 test_push_front_impl< Container >(1);
64 test_push_front_impl< Container >(2);
65 test_push_front_impl< Container >(100);
66 }
67
68 void test_push_front()
69 {
70 test_push_front_impl< std::vector<std::size_t> >();
71 test_push_front_impl< std::list<std::size_t> >();
72 }
73 }
74
75 boost::unit_test::test_suite*
76 init_unit_test_suite(int argc, char* argv[])
77 {
78 boost::unit_test::test_suite* test
79 = BOOST_TEST_SUITE( "RangeTestSuite.algorithm_ext.push_front" );
80
81 test->add( BOOST_TEST_CASE( &test_push_front ) );
82
83 return test;
84 }