blob: dfbb4a7fc82fc3b4ff0eebc57be4cecce75662a1 (
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
// 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/at_key.hpp>
#include <boost/hana/back.hpp>
#include <boost/hana/ext/std/tuple.hpp>
#include <boost/hana/front.hpp>
#include <boost/hana/integral_constant.hpp>
#include <tuple>
#include <utility>
namespace hana = boost::hana;
template <typename T>
T const& cref(T& t) { return t; }
// a non-movable, non-copyable type
struct RefOnly {
RefOnly() = default;
RefOnly(RefOnly const&) = delete;
RefOnly(RefOnly&&) = delete;
};
template <int i>
struct RefOnly_i : hana::int_<i> {
RefOnly_i() = default;
RefOnly_i(RefOnly_i const&) = delete;
RefOnly_i(RefOnly_i&&) = delete;
};
int main() {
std::tuple<RefOnly> t;
// Make sure that we return the proper reference types from `at`.
{
RefOnly&& r1 = hana::at_c<0>(std::move(t));
RefOnly& r2 = hana::at_c<0>(t);
RefOnly const& r3 = hana::at_c<0>(cref(t));
(void)r1; (void)r2; (void)r3;
}
// Make sure we return the proper reference types from `front`.
{
RefOnly&& r1 = hana::front(std::move(t));
RefOnly& r2 = hana::front(t);
RefOnly const& r3 = hana::front(cref(t));
(void)r1; (void)r2; (void)r3;
}
// Make sure we return the proper reference types from `back`.
{
RefOnly&& r1 = hana::back(std::move(t));
RefOnly& r2 = hana::back(t);
RefOnly const& r3 = hana::back(cref(t));
(void)r1; (void)r2; (void)r3;
}
// Make sure we return the proper reference types from `at_key`.
{
std::tuple<RefOnly_i<3>> t{};
RefOnly_i<3>& r1 = hana::at_key(t, RefOnly_i<3>{});
RefOnly_i<3> const& r2 = hana::at_key(cref(t), RefOnly_i<3>{});
RefOnly_i<3>&& r3 = hana::at_key(std::move(t), RefOnly_i<3>{});
(void)r1; (void)r2; (void)r3;
}
}
|