reversed_example.cpp 1.4 KB

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