]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/test/pair/cnstr.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/first.hpp>
7 #include <boost/hana/pair.hpp>
8 #include <boost/hana/second.hpp>
10 #include <type_traits>
12 namespace hana
= boost::hana
;
17 MoveOnly(MoveOnly
const&) = delete;
18 MoveOnly
& operator=(MoveOnly
const&) = delete;
19 MoveOnly(int data
) : 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 template <typename Target
>
35 constexpr operator Target() const { return Target
{}; }
40 NoMove(NoMove
const&) = delete;
41 NoMove(NoMove
&&) = delete;
44 // Note: It is also useful to check with a non-empty class, because that
45 // triggers different instantiations due to EBO.
46 struct NoMove_nonempty
{
47 NoMove_nonempty() = default;
48 NoMove_nonempty(NoMove_nonempty
const&) = delete;
49 NoMove_nonempty(NoMove_nonempty
&&) = delete;
55 hana::pair
<MoveOnly
, short> p1(MoveOnly
{3}, 4);
56 hana::pair
<MoveOnly
, short> p2(std::move(p1
));
57 BOOST_HANA_RUNTIME_CHECK(hana::first(p2
) == MoveOnly
{3});
58 BOOST_HANA_RUNTIME_CHECK(hana::second(p2
) == 4);
61 // Make sure it works across pair types
63 hana::pair
<MoveOnlyDerived
, short> p1(MoveOnlyDerived
{3}, 4);
64 hana::pair
<MoveOnly
, long> p2
= std::move(p1
);
65 BOOST_HANA_RUNTIME_CHECK(hana::first(p2
) == MoveOnly
{3});
66 BOOST_HANA_RUNTIME_CHECK(hana::second(p2
) == 4);
71 target1(target1
const&) = delete;
72 target1(target1
&&) = default;
77 target2(target2
const&) = delete;
78 target2(target2
&&) = default;
80 using Target
= hana::pair
<target1
, target2
>;
81 Target
p1(hana::make_pair(target1
{}, target2
{})); (void)p1
;
82 Target
p2(hana::make_pair(implicit_to
<target1
>{}, target2
{})); (void)p2
;
83 Target
p3(hana::make_pair(target1
{}, implicit_to
<target2
>{})); (void)p3
;
84 Target
p4(hana::make_pair(implicit_to
<target1
>{}, implicit_to
<target2
>{})); (void)p4
;
87 // Make sure we don't define the move constructor when it shouldn't be defined.
89 using Pair1
= hana::pair
<NoMove
, NoMove
>;
90 Pair1 pair1
; (void)pair1
;
91 static_assert(!std::is_move_constructible
<Pair1
>::value
, "");
93 using Pair2
= hana::pair
<NoMove_nonempty
, NoMove_nonempty
>;
94 Pair2 pair2
; (void)pair2
;
95 static_assert(!std::is_move_constructible
<Pair2
>::value
, "");