]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/test/pair/assign.move.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/config.hpp>
7 #include <boost/hana/first.hpp>
8 #include <boost/hana/pair.hpp>
9 #include <boost/hana/second.hpp>
12 namespace hana
= boost::hana
;
17 MoveOnly(MoveOnly
const&) = delete;
18 MoveOnly
& operator=(MoveOnly
const&) = delete;
19 MoveOnly(int data
= 1) : data_(data
) { }
20 MoveOnly(MoveOnly
&& x
) : data_(x
.data_
) { x
.data_
= 0; }
22 MoveOnly
& operator=(MoveOnly
&& x
)
23 { data_
= x
.data_
; x
.data_
= 0; return *this; }
25 bool operator==(const MoveOnly
& x
) const { return data_
== x
.data_
; }
28 struct MoveOnlyDerived
: MoveOnly
{
29 MoveOnlyDerived(MoveOnlyDerived
&&) = default;
30 MoveOnlyDerived(int data
= 1) : MoveOnly(data
) { }
33 constexpr auto in_constexpr_context(int a
, short b
) {
34 hana::pair
<int, short> p1(a
, b
);
35 hana::pair
<int, short> p2
;
36 hana::pair
<double, long> p3
;
43 // from pair<T, U> to pair<T, U>
45 hana::pair
<MoveOnly
, short> p1(MoveOnly
{3}, 4);
46 hana::pair
<MoveOnly
, short> p2
;
48 BOOST_HANA_RUNTIME_CHECK(hana::first(p2
) == MoveOnly
{3});
49 BOOST_HANA_RUNTIME_CHECK(hana::second(p2
) == 4);
52 // from pair<T, U> to pair<V, W>
54 hana::pair
<MoveOnlyDerived
, short> p1(MoveOnlyDerived
{3}, 4);
55 hana::pair
<MoveOnly
, long> p2
;
57 BOOST_HANA_RUNTIME_CHECK(hana::first(p2
) == MoveOnly
{3});
58 BOOST_HANA_RUNTIME_CHECK(hana::second(p2
) == 4);
61 // make sure that also works in a constexpr context
62 // (test fails under GCC <= 6 due to buggy constexpr)
63 #if BOOST_HANA_CONFIG_GCC >= BOOST_HANA_CONFIG_VERSION(7, 0, 0)
65 constexpr auto p
= in_constexpr_context(3, 4);
66 static_assert(hana::first(p
) == 3, "");
67 static_assert(hana::second(p
) == 4, "");