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 | //[indirected_example |
12 | #include <boost/range/adaptor/indirected.hpp> |
13 | #include <boost/range/algorithm/copy.hpp> |
14 | #include <boost/shared_ptr.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 indirected_example_test() |
28 | //-> |
29 | //=int main(int argc, const char* argv[]) |
30 | { |
31 | using namespace boost::adaptors; |
32 | |
33 | std::vector<boost::shared_ptr<int> > input; |
34 | |
35 | for (int i = 0; i < 10; ++i) |
36 | input.push_back(x: boost::shared_ptr<int>(new int(i))); |
37 | |
38 | boost::copy( |
39 | rng: input | indirected, |
40 | out: std::ostream_iterator<int>(std::cout, "," )); |
41 | |
42 | //= return 0; |
43 | //=} |
44 | //] |
45 | std::vector<int> reference; |
46 | for (int i = 0; i < 10; ++i) |
47 | reference.push_back(x: i); |
48 | |
49 | std::vector<int> test; |
50 | boost::push_back(on&: test, from: input | indirected); |
51 | |
52 | BOOST_CHECK_EQUAL_COLLECTIONS( reference.begin(), reference.end(), |
53 | test.begin(), test.end() ); |
54 | } |
55 | } |
56 | |
57 | boost::unit_test::test_suite* |
58 | init_unit_test_suite(int argc, char* argv[]) |
59 | { |
60 | boost::unit_test::test_suite* test |
61 | = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.indirected_example" ); |
62 | |
63 | test->add( BOOST_TEST_CASE( &indirected_example_test ) ); |
64 | |
65 | return test; |
66 | } |
67 | |