]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/container/test/pair_test.cpp
1 //////////////////////////////////////////////////////////////////////////////
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)
7 // See http://www.boost.org/libs/container for documentation.
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>
21 //movable_and_copyable_int
24 #include <boost/tuple/tuple.hpp>
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
30 #if defined(BOOST_CONTAINER_PAIR_TEST_HAS_HEADER_TUPLE)
34 using namespace ::boost::container
;
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
;
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);
51 { //Constructible from internal types
52 container_detail::pair
<test::copyable_int
, test::copyable_int
> p2(test::copyable_int(1), test::copyable_int(2));
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
));
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
));
62 { //piecewise construct from boost tuple
63 using namespace boost::tuples
;
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
);
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
);
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
);
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');
90 boost::container::container_detail::pair
91 < tuple
<int, float, double>
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');
100 #if defined(BOOST_CONTAINER_PAIR_TEST_HAS_HEADER_TUPLE)
101 { //piecewise construct from std tuple
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
);
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
);
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
);
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');
129 boost::container::container_detail::pair
130 < tuple
<int, float, double>
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');
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
))
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);
152 #endif //#!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_HDR_TUPLE)
153 return ::boost::report_errors();
156 #include <boost/container/detail/config_end.hpp>