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/phoenix/core.hpp> |
12 | #include <boost/phoenix/operator.hpp> |
13 | #include <boost/range/adaptor/transformed.hpp> |
14 | #include <boost/range/algorithm_ext/push_back.hpp> |
15 | #include <boost/test/test_tools.hpp> |
16 | #include <boost/test/unit_test.hpp> |
17 | #include <iterator> |
18 | #include <iostream> |
19 | #include <vector> |
20 | |
21 | namespace |
22 | { |
23 | struct test_struct |
24 | { |
25 | double x; |
26 | double y; |
27 | }; |
28 | |
29 | struct get_x |
30 | { |
31 | typedef double result_type; |
32 | double operator()(const test_struct& s) const |
33 | { |
34 | return s.x; |
35 | } |
36 | }; |
37 | |
38 | void range_transformed_warning() |
39 | { |
40 | using namespace boost::phoenix::arg_names; |
41 | using namespace boost::adaptors; |
42 | |
43 | test_struct t; |
44 | t.x = 2.0; |
45 | t.y = -4.0; |
46 | std::vector<test_struct> v(10u, t); |
47 | |
48 | std::vector<double> output1; |
49 | boost::push_back(on&: output1, from: v | transformed((&arg1)->*& test_struct::x)); |
50 | |
51 | std::vector<double> output2; |
52 | boost::push_back(on&: output2, from: v | transformed(get_x())); |
53 | |
54 | BOOST_CHECK_EQUAL_COLLECTIONS( |
55 | output1.begin(), output1.end(), |
56 | output2.begin(), output2.end()); |
57 | } |
58 | } // anonymous namespace |
59 | |
60 | boost::unit_test::test_suite* |
61 | init_unit_test_suite(int argc, char* argv[]) |
62 | { |
63 | boost::unit_test::test_suite* test |
64 | = BOOST_TEST_SUITE( "Range adaptors - transformed warning" ); |
65 | |
66 | test->add(BOOST_TEST_CASE(&range_transformed_warning)); |
67 | |
68 | return test; |
69 | } |
70 | |