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)
7 // For more information, see http://www.boost.org/libs/range/
9 #include <boost/range/algorithm/rotate_copy.hpp>
11 #include <boost/test/test_tools.hpp>
12 #include <boost/test/unit_test.hpp>
14 #include <boost/assign.hpp>
15 #include <boost/bind.hpp>
25 template<class OutputIterator
, class Value
>
26 void test_append(OutputIterator target
, Value value
)
31 template<class Container
, class Iterator
>
32 void test_rotate_copy_impl(Container
& cont
, Iterator where_it
)
34 typedef BOOST_DEDUCED_TYPENAME
boost::range_value
<Container
>::type
37 std::vector
<value_type
> reference
;
38 std::vector
<value_type
> test
;
40 typedef BOOST_DEDUCED_TYPENAME
boost::range_iterator
<Container
>::type
41 iterator_t BOOST_RANGE_UNUSED
;
44 std::rotate_copy(cont
.begin(), where_it
, cont
.end(),
45 std::back_inserter(reference
)),
50 boost::rotate_copy(cont
, where_it
, std::back_inserter(test
)),
54 BOOST_CHECK_EQUAL_COLLECTIONS( reference
.begin(), reference
.end(),
55 test
.begin(), test
.end() );
60 boost::rotate_copy(boost::make_iterator_range(cont
), where_it
,
61 std::back_inserter(test
)),
65 BOOST_CHECK_EQUAL_COLLECTIONS( reference
.begin(), reference
.end(),
66 test
.begin(), test
.end() );
69 template<class Container
>
70 void test_rotate_copy_impl(Container
& cont
)
72 typedef BOOST_DEDUCED_TYPENAME
boost::range_iterator
<Container
>::type iterator_t
;
74 iterator_t last
= cont
.end();
75 for (iterator_t it
= cont
.begin(); it
!= last
; ++it
)
77 test_rotate_copy_impl(cont
, it
);
81 template<class Container
>
82 void test_rotate_copy_impl()
84 using namespace boost::assign
;
87 test_rotate_copy_impl(cont
);
91 test_rotate_copy_impl(cont
);
94 cont
+= 1,2,3,4,5,6,7,8,9;
95 test_rotate_copy_impl(cont
);
98 void test_rotate_copy()
100 test_rotate_copy_impl
< std::vector
<int> >();
101 test_rotate_copy_impl
< std::list
<int> >();
102 test_rotate_copy_impl
< std::deque
<int> >();
106 boost::unit_test::test_suite
*
107 init_unit_test_suite(int argc
, char* argv
[])
109 boost::unit_test::test_suite
* test
110 = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.rotate_copy" );
112 test
->add( BOOST_TEST_CASE( &test_rotate_copy
) );