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 | class dummy_interface |
21 | { |
22 | public: |
23 | virtual ~dummy_interface() { } |
24 | virtual void test() = 0; |
25 | protected: |
26 | dummy_interface() { } |
27 | private: |
28 | dummy_interface(const dummy_interface&); |
29 | void operator=(const dummy_interface&); |
30 | }; |
31 | |
32 | class dummy_impl |
33 | : public dummy_interface |
34 | { |
35 | public: |
36 | dummy_impl() { } |
37 | dummy_impl(const dummy_impl&) { } |
38 | dummy_impl& operator=(const dummy_impl&) { return *this; } |
39 | virtual void test() { } |
40 | }; |
41 | |
42 | typedef boost::any_range< |
43 | dummy_interface, |
44 | boost::random_access_traversal_tag, |
45 | dummy_interface&, |
46 | std::ptrdiff_t |
47 | > any_interface_range; |
48 | |
49 | struct foo_dummy_interface_fn |
50 | { |
51 | void operator()(dummy_interface& iface) |
52 | { |
53 | iface.test(); |
54 | } |
55 | }; |
56 | |
57 | void foo_test_dummy_interface_range(any_interface_range rng) |
58 | { |
59 | std::for_each(first: boost::begin(r&: rng), last: boost::end(r&: rng), |
60 | f: foo_dummy_interface_fn()); |
61 | } |
62 | |
63 | void test_type_erased_abstract() |
64 | { |
65 | std::vector<dummy_impl> v(10); |
66 | |
67 | any_interface_range r(v); |
68 | |
69 | foo_test_dummy_interface_range(rng: r); |
70 | |
71 | foo_test_dummy_interface_range(rng: any_interface_range(v)); |
72 | } |
73 | |
74 | } // anonymous namespace |
75 | } // namespace boost_range_adaptor_type_erased_test |
76 | |
77 | boost::unit_test::test_suite* |
78 | init_unit_test_suite(int, char*[]) |
79 | { |
80 | boost::unit_test::test_suite* test |
81 | = BOOST_TEST_SUITE("RangeTestSuite.adaptor.type_erased_abstract"); |
82 | |
83 | test->add( |
84 | BOOST_TEST_CASE( |
85 | &boost_range_adaptor_type_erased_test::test_type_erased_abstract)); |
86 | |
87 | return test; |
88 | } |
89 |