| 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 | |
| 18 | #include <boost/test/test_tools.hpp> |
| 19 | #include <boost/test/unit_test.hpp> |
| 20 | |
| 21 | #include <list> |
| 22 | #include <vector> |
| 23 | #include <numeric> |
| 24 | |
| 25 | namespace boost |
| 26 | { |
| 27 | namespace |
| 28 | { |
| 29 | |
| 30 | void ticket_9519_strided_reversed_test() |
| 31 | { |
| 32 | using namespace boost::adaptors; |
| 33 | |
| 34 | std::vector<int> vi; |
| 35 | for (int i = 0; i < 50; ++i) |
| 36 | { |
| 37 | vi.push_back(x: i); |
| 38 | } |
| 39 | |
| 40 | std::vector<int> output; |
| 41 | boost::push_back(on&: output, from: vi | strided(3) | reversed); |
| 42 | |
| 43 | std::list<int> reference; |
| 44 | for (int i = 0; i < 50; i += 3) |
| 45 | { |
| 46 | reference.push_front(x: i); |
| 47 | } |
| 48 | |
| 49 | BOOST_CHECK_EQUAL_COLLECTIONS(output.begin(), output.end(), |
| 50 | reference.begin(), reference.end()); |
| 51 | } |
| 52 | |
| 53 | } // anonymous namespace |
| 54 | } // namespace boost |
| 55 | |
| 56 | boost::unit_test::test_suite* |
| 57 | init_unit_test_suite(int argc, char* argv[]) |
| 58 | { |
| 59 | boost::unit_test::test_suite* test |
| 60 | = BOOST_TEST_SUITE( |
| 61 | "RangeTestSuite.adaptor.ticket_9519_strided_reversed"); |
| 62 | |
| 63 | test->add(BOOST_TEST_CASE(&boost::ticket_9519_strided_reversed_test)); |
| 64 | |
| 65 | return test; |
| 66 | } |
| 67 | |
| 68 |
