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/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/range/iterator.hpp>
18#include <algorithm>
19#include <list>
20#include <set>
21#include <vector>
22
23namespace boost
24{
25 namespace
26 {
27 template< class Container >
28 void test_copy_impl()
29 {
30 Container source;
31 typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t;
32
33 std::vector<value_t> target;
34 target.resize(source.size());
35
36 typedef BOOST_DEDUCED_TYPENAME range_iterator< std::vector<value_t> >::type iterator_t;
37 iterator_t it = boost::copy(source, target.begin());
38
39 BOOST_CHECK( it == target.end() );
40
41 BOOST_CHECK_EQUAL_COLLECTIONS(
42 target.begin(), target.end(),
43 source.begin(), source.end()
44 );
45
46 it = boost::copy(boost::make_iterator_range(source), target.begin());
47
48 BOOST_CHECK( it == target.end() );
49
50 BOOST_CHECK_EQUAL_COLLECTIONS(target.begin(), target.end(),
51 source.begin(), source.end());
52 }
53
54 void test_copy()
55 {
56 test_copy_impl< std::vector<int> >();
57 test_copy_impl< std::list<int> >();
58 test_copy_impl< std::set<int> >();
59 test_copy_impl< std::multiset<int> >();
60 }
61 }
62}
63
64
65boost::unit_test::test_suite*
66init_unit_test_suite(int argc, char* argv[])
67{
68 boost::unit_test::test_suite* test
69 = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.copy" );
70
71 test->add( BOOST_TEST_CASE( &boost::test_copy ) );
72
73 return test;
74}
75

source code of boost/libs/range/test/algorithm_test/copy.cpp