| 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_n.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 | |
| 23 | namespace |
| 24 | { |
| 25 | template< class Container > |
| 26 | void test_copy_n_impl() |
| 27 | { |
| 28 | Container source; |
| 29 | typedef BOOST_DEDUCED_TYPENAME Container::value_type value_t; |
| 30 | |
| 31 | std::vector<value_t> target; |
| 32 | target.resize(source.size()); |
| 33 | |
| 34 | typedef BOOST_DEDUCED_TYPENAME range_iterator< std::vector<value_t> >::type iterator_t; |
| 35 | iterator_t it = boost::copy(src: source, dest: target.begin()); |
| 36 | |
| 37 | BOOST_CHECK( it == target.end() ); |
| 38 | |
| 39 | BOOST_CHECK_EQUAL_COLLECTIONS( |
| 40 | target.begin(), target.end(), |
| 41 | source.begin(), source.end() |
| 42 | ); |
| 43 | |
| 44 | it = boost::copy(src: boost::make_iterator_range(source), dest: target.begin()); |
| 45 | |
| 46 | BOOST_CHECK( it == target.end() ); |
| 47 | |
| 48 | BOOST_CHECK_EQUAL_COLLECTIONS(target.begin(), target.end(), |
| 49 | source.begin(), source.end()); |
| 50 | } |
| 51 | |
| 52 | void test_copy_n() |
| 53 | { |
| 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> >(); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | boost::unit_test::test_suite* |
| 62 | init_unit_test_suite(int argc, char* argv[]) |
| 63 | { |
| 64 | boost::unit_test::test_suite* test |
| 65 | = BOOST_TEST_SUITE( "RangeTestSuite.algorithm.copy_n" ); |
| 66 | |
| 67 | test->add( BOOST_TEST_CASE( &::test_copy_n ) ); |
| 68 | |
| 69 | return test; |
| 70 | } |
| 71 | |