• 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/first.hpp>
6 #include <boost/hana/pair.hpp>
7 #include <boost/hana/second.hpp>
8 
9 #include <utility>
10 namespace hana = boost::hana;
11 
12 
13 template <typename T>
cref(T & t)14 T const& cref(T& t) { return t; }
15 
16 // a non-movable, non-copyable type
17 struct RefOnly {
18     RefOnly() = default;
19     RefOnly(RefOnly const&) = delete;
20     RefOnly(RefOnly&&) = delete;
21 };
22 
main()23 int main() {
24     // This test makes sure that we return the proper reference types from
25     // `first` and `second`.
26     hana::pair<RefOnly, RefOnly> p;
27 
28     {
29         RefOnly&& r1 = hana::first(std::move(p));
30         RefOnly& r2 = hana::first(p);
31         RefOnly const& r3 = hana::first(cref(p));
32 
33         (void)r1; (void)r2; (void)r3;
34     }
35 
36     {
37         RefOnly&& r1 = hana::second(std::move(p));
38         RefOnly& r2 = hana::second(p);
39         RefOnly const& r3 = hana::second(cref(p));
40 
41         (void)r1; (void)r2; (void)r3;
42     }
43 }
44