copied_example.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. //[copied_example
  12. #include <boost/range/adaptor/copied.hpp>
  13. #include <boost/range/algorithm/copy.hpp>
  14. #include <boost/assign.hpp>
  15. #include <iterator>
  16. #include <iostream>
  17. #include <vector>
  18. //<-
  19. #include <boost/range/algorithm_ext/push_back.hpp>
  20. #include <boost/test/test_tools.hpp>
  21. #include <boost/test/unit_test.hpp>
  22. namespace
  23. {
  24. void copied_example_test()
  25. //->
  26. //=int main(int argc, const char* argv[])
  27. {
  28. using namespace boost::assign;
  29. using namespace boost::adaptors;
  30. std::vector<int> input;
  31. input += 1,2,3,4,5,6,7,8,9,10;
  32. boost::copy(
  33. input | copied(1, 5),
  34. std::ostream_iterator<int>(std::cout, ","));
  35. //= return 0;
  36. //=}
  37. //]
  38. std::vector<int> reference;
  39. reference += 2,3,4,5;
  40. std::vector<int> test;
  41. boost::push_back(test, input | copied(1, 5));
  42. BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(),
  43. test.begin(), test.end() );
  44. }
  45. }
  46. boost::unit_test::test_suite*
  47. init_unit_test_suite(int argc, char* argv[])
  48. {
  49. boost::unit_test::test_suite* test
  50. = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.copied_example" );
  51. test->add( BOOST_TEST_CASE( &copied_example_test ) );
  52. return test;
  53. }