]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/container/test/pair_test.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / container / test / pair_test.cpp
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2011-2013. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // See http://www.boost.org/libs/container for documentation.
8 //
9 //////////////////////////////////////////////////////////////////////////////
10 #include <boost/container/detail/config_begin.hpp>
11 #include <boost/container/detail/pair.hpp>
12 #include "movable_int.hpp"
13 #include "emplace_test.hpp"
14 #include<boost/move/utility_core.hpp>
15 #include<boost/move/detail/fwd_macros.hpp>
16 #include<boost/core/lightweight_test.hpp>
17
18 //non_copymovable_int
19 //copyable_int
20 //movable_int
21 //movable_and_copyable_int
22
23
24 #include <boost/tuple/tuple.hpp>
25
26 #if !defined(BOOST_NO_CXX11_HDR_TUPLE) || (defined(BOOST_MSVC) && (BOOST_MSVC == 1700 || BOOST_MSVC == 1600))
27 #define BOOST_CONTAINER_PAIR_TEST_HAS_HEADER_TUPLE
28 #endif
29
30 #if defined(BOOST_CONTAINER_PAIR_TEST_HAS_HEADER_TUPLE)
31 #include <tuple>
32 #endif
33
34 using namespace ::boost::container;
35
36 int main ()
37 {
38 {
39 container_detail::pair<test::non_copymovable_int, test::non_copymovable_int> p1;
40 container_detail::pair<test::copyable_int, test::copyable_int> p2;
41 container_detail::pair<test::movable_int, test::movable_int> p3;
42 container_detail::pair<test::movable_and_copyable_int, test::movable_and_copyable_int> p4;
43 }
44 { //Constructible from two values
45 container_detail::pair<test::non_copymovable_int, test::non_copymovable_int> p1(1, 2);
46 container_detail::pair<test::copyable_int, test::copyable_int> p2(1, 2);
47 container_detail::pair<test::movable_int, test::movable_int> p3(1, 2);
48 container_detail::pair<test::movable_and_copyable_int, test::movable_and_copyable_int> p4(1, 2);
49 }
50
51 { //Constructible from internal types
52 container_detail::pair<test::copyable_int, test::copyable_int> p2(test::copyable_int(1), test::copyable_int(2));
53 {
54 test::movable_int a(1), b(2);
55 container_detail::pair<test::movable_int, test::movable_int> p3(::boost::move(a), ::boost::move(b));
56 }
57 {
58 test::movable_and_copyable_int a(1), b(2);
59 container_detail::pair<test::movable_and_copyable_int, test::movable_and_copyable_int> p4(::boost::move(a), ::boost::move(b));
60 }
61 }
62 { //piecewise construct from boost tuple
63 using namespace boost::tuples;
64 {
65 boost::container::container_detail::pair<int, float> p(piecewise_construct, tuple<>(), tuple<>());
66 BOOST_TEST(p.first == 0);
67 BOOST_TEST(p.second == 0.f);
68 }
69 {
70 boost::container::container_detail::pair<int, float> p(piecewise_construct, tuple<>(), tuple<float>(2.f));
71 BOOST_TEST(p.first == 0);
72 BOOST_TEST(p.second == 2.f);
73 }
74 {
75 boost::container::container_detail::pair<int, float> p(piecewise_construct, tuple<int>(2), tuple<float>(1.f));
76 BOOST_TEST(p.first == 2);
77 BOOST_TEST(p.second == 1.f);
78 }
79 {
80 boost::container::container_detail::pair
81 < boost::container::container_detail::pair<int, float>
82 , boost::container::container_detail::pair<double, char>
83 > p(piecewise_construct, tuple<int, float>(3, 4.f), tuple<double, char>(8.,'a'));
84 BOOST_TEST(p.first.first == 3);
85 BOOST_TEST(p.first.second == 4.f);
86 BOOST_TEST(p.second.first == 8.);
87 BOOST_TEST(p.second.second == 'a');
88 }
89 {
90 boost::container::container_detail::pair
91 < tuple<int, float, double>
92 , char
93 > p(piecewise_construct, tuple<int, float, double>(3, 16.f, 32.), tuple<char>('b'));
94 BOOST_TEST(p.first.get<0>() == 3);
95 BOOST_TEST(p.first.get<1>() == 16.f);
96 BOOST_TEST(p.first.get<2>() == 32.);
97 BOOST_TEST(p.second == 'b');
98 }
99 }
100 #if defined(BOOST_CONTAINER_PAIR_TEST_HAS_HEADER_TUPLE)
101 { //piecewise construct from std tuple
102 using std::tuple;
103 {
104 boost::container::container_detail::pair<int, float> p(piecewise_construct, tuple<>(), tuple<>());
105 BOOST_TEST(p.first == 0);
106 BOOST_TEST(p.second == 0.f);
107 }
108 {
109 boost::container::container_detail::pair<int, float> p(piecewise_construct, tuple<>(), tuple<float>(2.f));
110 BOOST_TEST(p.first == 0);
111 BOOST_TEST(p.second == 2.f);
112 }
113 {
114 boost::container::container_detail::pair<int, float> p(piecewise_construct, tuple<int>(2), tuple<float>(1.f));
115 BOOST_TEST(p.first == 2);
116 BOOST_TEST(p.second == 1.f);
117 }
118 {
119 boost::container::container_detail::pair
120 < boost::container::container_detail::pair<int, float>
121 , boost::container::container_detail::pair<double, char>
122 > p(piecewise_construct, tuple<int, float>(3, 4.f), tuple<double, char>(8.,'a'));
123 BOOST_TEST(p.first.first == 3);
124 BOOST_TEST(p.first.second == 4.f);
125 BOOST_TEST(p.second.first == 8.);
126 BOOST_TEST(p.second.second == 'a');
127 }
128 {
129 boost::container::container_detail::pair
130 < tuple<int, float, double>
131 , char
132 > p(piecewise_construct, tuple<int, float, double>(3, 16.f, 32.), tuple<char>('b'));
133 BOOST_TEST(std::get<0>(p.first) == 3);
134 BOOST_TEST(std::get<1>(p.first) == 16.f);
135 BOOST_TEST(std::get<2>(p.first) == 32.);
136 BOOST_TEST(p.second == 'b');
137 }
138 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
139 typedef container_detail::pair<test::movable_int, test::movable_int> movable_pair_t;
140 typedef container_detail::pair<movable_pair_t, movable_pair_t> movable_pair_pair_t;
141 test::movable_int a(1), b(2), c(3), d(4);
142 movable_pair_pair_t p( piecewise_construct
143 , container_detail::forward_as_tuple(boost::move(a), boost::move(b))
144 , container_detail::forward_as_tuple(boost::move(c), boost::move(d))
145 );
146 BOOST_TEST(p.first.first == 1);
147 BOOST_TEST(p.first.second == 2);
148 BOOST_TEST(p.second.first == 3);
149 BOOST_TEST(p.second.second == 4);
150 #endif
151 }
152 #endif //#!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_HDR_TUPLE)
153 return ::boost::report_errors();
154 }
155
156 #include <boost/container/detail/config_end.hpp>