]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/range/test/adaptor_test/ref_unwrapped.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / range / test / adaptor_test / ref_unwrapped.cpp
1 // Boost.Range library
2 //
3 // Copyright Robin Eckert 2015. Use, modification and distribution is
4 // subject to the Boost Software License, Version 1.0. (See
5 // 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/range/adaptor/ref_unwrapped.hpp>
12
13 #define BOOST_TEST_MAIN
14
15 #include <boost/test/test_tools.hpp>
16 #include <boost/test/unit_test.hpp>
17
18 #include <vector>
19
20 #if !defined(BOOST_NO_CXX11_AUTO_DECLARATIONS) && !defined(BOOST_NO_CXX11_RANGE_BASED_FOR) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX)
21
22 namespace boost
23 {
24
25 BOOST_AUTO_TEST_CASE(test_mutable)
26 {
27 int one = 1;
28 int two = 2;
29 int three = 3;
30
31 std::vector<std::reference_wrapper<int>> input_values{one, two, three};
32
33 const std::vector<int*> expected{&one, &two, &three};
34 std::vector<int*> actual;
35
36 for (auto&& value : input_values | adaptors::ref_unwrapped)
37 {
38 actual.push_back(&value);
39 }
40
41 BOOST_CHECK_EQUAL_COLLECTIONS(expected.begin(),
42 expected.end(),
43 actual.begin(),
44 actual.end());
45 }
46
47 BOOST_AUTO_TEST_CASE(test_const_range)
48 {
49 int one = 1;
50 int two = 2;
51 int three = 3;
52
53 const std::vector<std::reference_wrapper<int>> input_values{one, two, three};
54
55 const std::vector<int*> expected{&one, &two, &three};
56 std::vector<int*> actual;
57
58 for (auto&& value : input_values | adaptors::ref_unwrapped)
59 {
60 actual.push_back(&value);
61 }
62
63 BOOST_CHECK_EQUAL_COLLECTIONS(expected.begin(),
64 expected.end(),
65 actual.begin(),
66 actual.end());
67 }
68
69 BOOST_AUTO_TEST_CASE(test_const_reference)
70 {
71 const int one = 1;
72 const int two = 2;
73 const int three = 3;
74
75 const std::vector<std::reference_wrapper<const int>> input_values{one, two, three};
76
77 const std::vector<const int*> expected{&one, &two, &three};
78 std::vector<const int*> actual;
79
80 for (auto&& value : input_values | adaptors::ref_unwrapped)
81 {
82 actual.push_back(&value);
83 }
84
85 BOOST_CHECK_EQUAL_COLLECTIONS(expected.begin(),
86 expected.end(),
87 actual.begin(),
88 actual.end());
89 }
90
91
92 }
93
94 #else
95
96 BOOST_AUTO_TEST_CASE(empty)
97 {
98 // C++11 only
99 }
100
101 #endif