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 "type_erased_test.hpp" |
10 | |
11 | #include <boost/test/unit_test.hpp> |
12 | |
13 | #include <vector> |
14 | |
15 | namespace boost_range_adaptor_type_erased_test |
16 | { |
17 | namespace |
18 | { |
19 | |
20 | template< |
21 | class Traversal |
22 | , class ValueType |
23 | , class SourceValueType |
24 | , class SourceReference |
25 | , class TargetValueType |
26 | , class TargetReference |
27 | > |
28 | void mix_values_impl() |
29 | { |
30 | typedef std::vector<ValueType> Container; |
31 | |
32 | typedef typename boost::any_range_type_generator< |
33 | Container |
34 | , SourceValueType |
35 | , Traversal |
36 | , SourceReference |
37 | >::type source_type; |
38 | |
39 | typedef typename boost::any_range_type_generator< |
40 | Container |
41 | , TargetValueType |
42 | , Traversal |
43 | , TargetReference |
44 | >::type target_type; |
45 | |
46 | Container test_data; |
47 | for (int i = 0; i < 10; ++i) |
48 | test_data.push_back(i); |
49 | |
50 | const source_type source_data(test_data); |
51 | target_type t1(source_data); |
52 | BOOST_CHECK_EQUAL_COLLECTIONS(source_data.begin(), source_data.end(), |
53 | t1.begin(), t1.end()); |
54 | |
55 | target_type t2; |
56 | t2 = source_data; |
57 | BOOST_CHECK_EQUAL_COLLECTIONS(source_data.begin(), source_data.end(), |
58 | t2.begin(), t2.end()); |
59 | } |
60 | |
61 | template<class Traversal> |
62 | void mix_values_driver() |
63 | { |
64 | mix_values_impl< |
65 | Traversal, |
66 | MockType, |
67 | MockType2, const MockType&, |
68 | MockType, const MockType& |
69 | >(); |
70 | } |
71 | |
72 | void mix_values() |
73 | { |
74 | mix_values_driver<boost::single_pass_traversal_tag >(); |
75 | mix_values_driver<boost::forward_traversal_tag >(); |
76 | mix_values_driver<boost::bidirectional_traversal_tag >(); |
77 | mix_values_driver<boost::random_access_traversal_tag >(); |
78 | } |
79 | |
80 | } // anonymous namespace |
81 | } // namespace boost_range_adaptor_type_erased_test |
82 | |
83 | boost::unit_test::test_suite* |
84 | init_unit_test_suite(int, char*[]) |
85 | { |
86 | boost::unit_test::test_suite* test = |
87 | BOOST_TEST_SUITE("RangeTestSuite.adaptor.type_erased_mix_values" ); |
88 | |
89 | test->add(BOOST_TEST_CASE( |
90 | &boost_range_adaptor_type_erased_test::mix_values)); |
91 | |
92 | return test; |
93 | } |
94 | |
95 | |