• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)
4 
5 #include <boost/hana/at.hpp>
6 #include <boost/hana/at_key.hpp>
7 #include <boost/hana/back.hpp>
8 #include <boost/hana/ext/std/tuple.hpp>
9 #include <boost/hana/front.hpp>
10 #include <boost/hana/integral_constant.hpp>
11 
12 #include <tuple>
13 #include <utility>
14 namespace hana = boost::hana;
15 
16 
17 template <typename T>
cref(T & t)18 T const& cref(T& t) { return t; }
19 
20 // a non-movable, non-copyable type
21 struct RefOnly {
22     RefOnly() = default;
23     RefOnly(RefOnly const&) = delete;
24     RefOnly(RefOnly&&) = delete;
25 };
26 
27 template <int i>
28 struct RefOnly_i : hana::int_<i> {
29     RefOnly_i() = default;
30     RefOnly_i(RefOnly_i const&) = delete;
31     RefOnly_i(RefOnly_i&&) = delete;
32 };
33 
main()34 int main() {
35     std::tuple<RefOnly> t;
36 
37     // Make sure that we return the proper reference types from `at`.
38     {
39         RefOnly&& r1 = hana::at_c<0>(std::move(t));
40         RefOnly& r2 = hana::at_c<0>(t);
41         RefOnly const& r3 = hana::at_c<0>(cref(t));
42 
43         (void)r1; (void)r2; (void)r3;
44     }
45 
46     // Make sure we return the proper reference types from `front`.
47     {
48         RefOnly&& r1 = hana::front(std::move(t));
49         RefOnly& r2 = hana::front(t);
50         RefOnly const& r3 = hana::front(cref(t));
51 
52         (void)r1; (void)r2; (void)r3;
53     }
54 
55     // Make sure we return the proper reference types from `back`.
56     {
57         RefOnly&& r1 = hana::back(std::move(t));
58         RefOnly& r2 = hana::back(t);
59         RefOnly const& r3 = hana::back(cref(t));
60 
61         (void)r1; (void)r2; (void)r3;
62     }
63 
64     // Make sure we return the proper reference types from `at_key`.
65     {
66         std::tuple<RefOnly_i<3>> t{};
67         RefOnly_i<3>& r1 = hana::at_key(t, RefOnly_i<3>{});
68         RefOnly_i<3> const& r2 = hana::at_key(cref(t), RefOnly_i<3>{});
69         RefOnly_i<3>&& r3 = hana::at_key(std::move(t), RefOnly_i<3>{});
70 
71         (void)r1; (void)r2; (void)r3;
72     }
73 }
74