]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/hana/test/pair/assign.move.cpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / hana / test / pair / assign.move.cpp
CommitLineData
7c673cae
FG
1// Copyright Louis Dionne 2013-2016
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)
4
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
10#include <utility>
11namespace hana = boost::hana;
12
13
14struct MoveOnly {
15 int data_;
16 MoveOnly(MoveOnly const&) = delete;
17 MoveOnly& operator=(MoveOnly const&) = delete;
18 MoveOnly(int data = 1) : data_(data) { }
19 MoveOnly(MoveOnly&& x) : data_(x.data_) { x.data_ = 0; }
20
21 MoveOnly& operator=(MoveOnly&& x)
22 { data_ = x.data_; x.data_ = 0; return *this; }
23
24 bool operator==(const MoveOnly& x) const { return data_ == x.data_; }
25};
26
27struct MoveOnlyDerived : MoveOnly {
28 MoveOnlyDerived(MoveOnlyDerived&&) = default;
29 MoveOnlyDerived(int data = 1) : MoveOnly(data) { }
30};
31
32constexpr auto in_constexpr_context(int a, short b) {
33 hana::pair<int, short> p1(a, b);
34 hana::pair<int, short> p2;
35 hana::pair<double, long> p3;
36 p2 = std::move(p1);
37 p3 = std::move(p2);
38 return p3;
39}
40
41int main() {
42 // from pair<T, U> to pair<T, U>
43 {
44 hana::pair<MoveOnly, short> p1(MoveOnly{3}, 4);
45 hana::pair<MoveOnly, short> p2;
46 p2 = std::move(p1);
47 BOOST_HANA_RUNTIME_CHECK(hana::first(p2) == MoveOnly{3});
48 BOOST_HANA_RUNTIME_CHECK(hana::second(p2) == 4);
49 }
50
51 // from pair<T, U> to pair<V, W>
52 {
53 hana::pair<MoveOnlyDerived, short> p1(MoveOnlyDerived{3}, 4);
54 hana::pair<MoveOnly, long> p2;
55 p2 = std::move(p1);
56 BOOST_HANA_RUNTIME_CHECK(hana::first(p2) == MoveOnly{3});
57 BOOST_HANA_RUNTIME_CHECK(hana::second(p2) == 4);
58 }
59
60 // make sure that also works in a constexpr context
61 {
62 constexpr auto p = in_constexpr_context(3, 4);
63 static_assert(hana::first(p) == 3, "");
64 static_assert(hana::second(p) == 4, "");
65 }
66}