copy.cpp 2.0 KB

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