summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/hana/test/tuple/move_only.cpp
blob: 3f78316ccdcc08a562d8c591c6cb114f2b658cdc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright Louis Dionne 2013-2017
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)

#include <boost/hana/at.hpp>
#include <boost/hana/back.hpp>
#include <boost/hana/front.hpp>
#include <boost/hana/tuple.hpp>

#include <utility>
namespace hana = boost::hana;


// This test checks for move-only friendliness and reference semantics.

struct MoveOnly {
    MoveOnly() = default;
    MoveOnly(MoveOnly&&) = default;
    MoveOnly& operator=(MoveOnly&&) = default;

    MoveOnly(MoveOnly const&) = delete;
    MoveOnly& operator=(MoveOnly const&) = delete;
};

int main() {
    {
        auto xs = hana::make_tuple(MoveOnly{});
        auto by_val = [](auto) { };

        by_val(std::move(xs));
        by_val(hana::front(std::move(xs)));
        by_val(hana::at_c<0>(std::move(xs)));
        by_val(hana::back(std::move(xs)));
    }

    {
        auto const& xs = hana::make_tuple(MoveOnly{});
        auto by_const_ref = [](auto const&) { };

        by_const_ref(xs);
        by_const_ref(hana::front(xs));
        by_const_ref(hana::at_c<0>(xs));
        by_const_ref(hana::back(xs));
    }

    {
        auto xs = hana::make_tuple(MoveOnly{});
        auto by_ref = [](auto&) { };

        by_ref(xs);
        by_ref(hana::front(xs));
        by_ref(hana::at_c<0>(xs));
        by_ref(hana::back(xs));
    }
}