ticket_9519_strided_reversed.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Boost.Range library
  2. //
  3. // Copyright Neil Groves 2014. 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. // Credit goes to Eric Niebler for providing an example to demonstrate this
  12. // issue. This has been trivially modified to create this test case.
  13. //
  14. #include <boost/range/adaptor/strided.hpp>
  15. #include <boost/range/adaptor/reversed.hpp>
  16. #include <boost/range/algorithm_ext/push_back.hpp>
  17. #include <boost/test/test_tools.hpp>
  18. #include <boost/test/unit_test.hpp>
  19. #include <list>
  20. #include <vector>
  21. #include <numeric>
  22. namespace boost
  23. {
  24. namespace
  25. {
  26. void ticket_9519_strided_reversed_test()
  27. {
  28. using namespace boost::adaptors;
  29. std::vector<int> vi;
  30. for (int i = 0; i < 50; ++i)
  31. {
  32. vi.push_back(i);
  33. }
  34. std::vector<int> output;
  35. boost::push_back(output, vi | strided(3) | reversed);
  36. std::list<int> reference;
  37. for (int i = 0; i < 50; i += 3)
  38. {
  39. reference.push_front(i);
  40. }
  41. BOOST_CHECK_EQUAL_COLLECTIONS(output.begin(), output.end(),
  42. reference.begin(), reference.end());
  43. }
  44. } // anonymous namespace
  45. } // namespace boost
  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(
  51. "RangeTestSuite.adaptor.ticket_9519_strided_reversed");
  52. test->add(BOOST_TEST_CASE(&boost::ticket_9519_strided_reversed_test));
  53. return test;
  54. }