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