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 | #include <boost/range/adaptor/type_erased.hpp> |
9 | #include <boost/range/adaptor/transformed.hpp> |
10 | #include <boost/range/numeric.hpp> |
11 | #include "type_erased_test.hpp" |
12 | |
13 | #include <boost/test/unit_test.hpp> |
14 | |
15 | #include <vector> |
16 | |
17 | namespace boost_range_adaptor_type_erased_test |
18 | { |
19 | namespace |
20 | { |
21 | |
22 | typedef boost::any_range< |
23 | int, |
24 | boost::random_access_traversal_tag, |
25 | int, |
26 | std::ptrdiff_t |
27 | > any_integer_value_range; |
28 | |
29 | struct get_fn |
30 | { |
31 | typedef boost::int32_t result_type; |
32 | boost::int32_t operator()(const MockType& val) const |
33 | { |
34 | return val.get(); |
35 | } |
36 | }; |
37 | |
38 | int accumulate_any_integer_value_range(any_integer_value_range rng) |
39 | { |
40 | return boost::accumulate(rng, init: 0); |
41 | } |
42 | |
43 | void test_type_erased_transformed() |
44 | { |
45 | std::vector<MockType> v(5, MockType(3)); |
46 | |
47 | const int sum = accumulate_any_integer_value_range( |
48 | rng: v | boost::adaptors::transformed(get_fn())); |
49 | |
50 | BOOST_CHECK_EQUAL(15, sum); |
51 | } |
52 | |
53 | } // anonymous namespace |
54 | } // namespace boost_range_adaptor_type_erased_test |
55 | |
56 | boost::unit_test::test_suite* |
57 | init_unit_test_suite(int, char*[]) |
58 | { |
59 | boost::unit_test::test_suite* test |
60 | = BOOST_TEST_SUITE("RangeTestSuite.adaptor.type_erased_transformed"); |
61 | |
62 | test->add( |
63 | BOOST_TEST_CASE( |
64 | &boost_range_adaptor_type_erased_test::test_type_erased_transformed)); |
65 | |
66 | return test; |
67 | } |
68 |