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