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#include <boost/range/adaptor/sliced.hpp>
12#include <boost/range/adaptor/transformed.hpp>
13#include <boost/range/algorithm_ext/push_back.hpp>
14#include <boost/test/test_tools.hpp>
15#include <boost/test/unit_test.hpp>
16#include <vector>
17
18namespace
19{
20 struct identity
21 {
22 typedef int result_type;
23 result_type operator()(int i) const { return i; }
24 };
25
26 void sliced_and_transformed()
27 {
28 using namespace boost::adaptors;
29
30 std::vector<int> input;
31 for (int i = 0; i < 10; ++i)
32 input.push_back(x: i);
33
34 std::vector<int> out1;
35 boost::push_back(on&: out1, from: input | sliced(2, 8)
36 | transformed(identity()));
37
38 std::vector<int> out2;
39 boost::push_back(on&: out2, from: input | transformed(identity())
40 | sliced(2, 8));
41
42 BOOST_CHECK_EQUAL_COLLECTIONS(out1.begin(), out1.end(),
43 out2.begin(), out2.end());
44 }
45} // anonymous namespace
46
47boost::unit_test::test_suite*
48init_unit_test_suite(int argc, char* argv[])
49{
50 boost::unit_test::test_suite* test
51 = BOOST_TEST_SUITE( "Range adaptors - sliced and transformed" );
52
53 test->add(BOOST_TEST_CASE(&sliced_and_transformed));
54
55 return test;
56}
57

source code of boost/libs/range/test/adaptor_test/ticket_8676_sliced_transformed.cpp