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)
9 // For more information, see http://www.boost.org/libs/range/
11 #include <boost/range/algorithm/copy_n.hpp>
13 #include <boost/test/test_tools.hpp>
14 #include <boost/test/unit_test.hpp>
16 #include <boost/assign.hpp>
17 #include <boost/range/iterator.hpp>
25 template< class Container
>
26 void test_copy_n_impl()
29 typedef BOOST_DEDUCED_TYPENAME
Container::value_type value_t
;
31 std::vector
<value_t
> target
;
32 target
.resize(source
.size());
34 typedef BOOST_DEDUCED_TYPENAME range_iterator
< std::vector
<value_t
> >::type iterator_t
;
35 iterator_t it
= boost::copy(source
, target
.begin());
37 BOOST_CHECK( it
== target
.end() );
39 BOOST_CHECK_EQUAL_COLLECTIONS(
40 target
.begin(), target
.end(),
41 source
.begin(), source
.end()
44 it
= boost::copy(boost::make_iterator_range(source
), target
.begin());
46 BOOST_CHECK( it
== target
.end() );
48 BOOST_CHECK_EQUAL_COLLECTIONS(target
.begin(), target
.end(),
49 source
.begin(), source
.end());
54 test_copy_n_impl
< std::vector
<int> >();
55 test_copy_n_impl
< std::list
<int> >();
56 test_copy_n_impl
< std::set
<int> >();
57 test_copy_n_impl
< std::multiset
<int> >();
61 boost::unit_test::test_suite
*
62 init_unit_test_suite(int argc
, char* argv
[])
64 boost::unit_test::test_suite
* test
65 = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.copy_n" );
67 test
->add( BOOST_TEST_CASE( &::test_copy_n
) );