]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/test/pair/cnstr.memberwise.cpp
1 // Copyright Louis Dionne 2013-2017
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
5 #include <boost/hana/assert.hpp>
6 #include <boost/hana/first.hpp>
7 #include <boost/hana/pair.hpp>
8 #include <boost/hana/second.hpp>
9 namespace hana
= boost::hana
;
14 MoveOnly(MoveOnly
const&) = delete;
15 MoveOnly
& operator=(MoveOnly
const&) = delete;
16 MoveOnly(int data
) : data_(data
) { }
17 MoveOnly(MoveOnly
&& x
) : data_(x
.data_
) { x
.data_
= 0; }
19 MoveOnly
& operator=(MoveOnly
&& x
)
20 { data_
= x
.data_
; x
.data_
= 0; return *this; }
22 bool operator==(const MoveOnly
& x
) const { return data_
== x
.data_
; }
28 constexpr FromInt(int data
) : data_(data
) { }
29 constexpr bool operator==(const FromInt
& x
) const { return data_
== x
.data_
; }
33 //////////////////////////////////////////////////////////////////////////
34 // Check for the pair(T&&, U&&) constructor
35 //////////////////////////////////////////////////////////////////////////
37 hana::pair
<MoveOnly
, short*> p(MoveOnly
{3}, nullptr);
38 BOOST_HANA_RUNTIME_CHECK(hana::first(p
) == MoveOnly
{3});
39 BOOST_HANA_RUNTIME_CHECK(hana::second(p
) == nullptr);
42 //////////////////////////////////////////////////////////////////////////
43 // Check for the pair(First const&, Second const&) constructor
44 //////////////////////////////////////////////////////////////////////////
46 hana::pair
<float, short*> p1(3.5f
, 0);
47 BOOST_HANA_RUNTIME_CHECK(hana::first(p1
) == 3.5f
);
48 BOOST_HANA_RUNTIME_CHECK(hana::second(p1
) == nullptr);
51 hana::pair
<float, short*> p2
= {3.5f
, 0};
52 BOOST_HANA_RUNTIME_CHECK(hana::first(p2
) == 3.5f
);
53 BOOST_HANA_RUNTIME_CHECK(hana::second(p2
) == nullptr);
56 hana::pair
<FromInt
, int> p1(1, 2);
57 BOOST_HANA_RUNTIME_CHECK(hana::first(p1
) == FromInt(1));
58 BOOST_HANA_RUNTIME_CHECK(hana::second(p1
) == 2);
61 hana::pair
<FromInt
, int> p2
= {1, 2};
62 BOOST_HANA_RUNTIME_CHECK(hana::first(p2
) == FromInt(1));
63 BOOST_HANA_RUNTIME_CHECK(hana::second(p2
) == 2);
66 // Make sure the above works constexpr too
68 constexpr hana::pair
<float, short*> p1(3.5f
, 0);
69 static_assert(hana::first(p1
) == 3.5f
, "");
70 static_assert(hana::second(p1
) == nullptr, "");
73 constexpr hana::pair
<float, short*> p2
= {3.5f
, 0};
74 static_assert(hana::first(p2
) == 3.5f
, "");
75 static_assert(hana::second(p2
) == nullptr, "");
78 constexpr hana::pair
<FromInt
, int> p1(1, 2);
79 static_assert(hana::first(p1
) == FromInt(1), "");
80 static_assert(hana::second(p1
) == 2, "");
83 constexpr hana::pair
<FromInt
, int> p2
= {1, 2};
84 static_assert(hana::first(p2
) == FromInt(1), "");
85 static_assert(hana::second(p2
) == 2, "");