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)
5 #include <boost/hana/assert.hpp>
6 #include <boost/hana/first.hpp>
7 #include <boost/hana/pair.hpp>
8 #include <boost/hana/second.hpp>
10 #include <type_traits>
11 namespace hana
= boost::hana
;
14 template <typename Target
>
16 constexpr operator Target() const { return Target
{}; }
21 NoCopy(NoCopy
const&) = delete;
24 // Note: It is also useful to check with a non-empty class, because that
25 // triggers different instantiations due to EBO.
26 struct NoCopy_nonempty
{
27 NoCopy_nonempty() = default;
28 NoCopy_nonempty(NoCopy_nonempty
const&) = delete;
34 typedef std::pair
<int, short> P1
;
35 hana::pair
<int, short> p1(3, 4);
36 hana::pair
<int, short> p2
= p1
;
37 BOOST_HANA_RUNTIME_CHECK(hana::first(p2
) == 3);
38 BOOST_HANA_RUNTIME_CHECK(hana::second(p2
) == 4);
41 static_assert(std::is_trivially_copy_constructible
<hana::pair
<int, int>>{}, "");
43 // make sure it also works constexpr
45 constexpr hana::pair
<int, short> p1(3, 4);
46 constexpr hana::pair
<int, short> p2
= p1
;
47 static_assert(hana::first(p2
) == 3, "");
48 static_assert(hana::second(p2
) == 4, "");
51 // Make sure it works across pair types (pair<T, U> -> pair<U, V>)
53 hana::pair
<int, short> p1(3, 4);
54 hana::pair
<double, long> p2
= p1
;
55 BOOST_HANA_RUNTIME_CHECK(hana::first(p2
) == 3);
56 BOOST_HANA_RUNTIME_CHECK(hana::second(p2
) == 4);
61 using Target
= hana::pair
<target1
, target2
>;
63 auto p1_
= hana::make_pair(target1
{}, target2
{});
64 Target
p1(p1_
); (void)p1
;
66 auto p2_
= hana::make_pair(implicit_to
<target1
>{}, target2
{});
69 auto p3_
= hana::make_pair(target1
{}, implicit_to
<target2
>{});
72 auto p4_
= hana::make_pair(implicit_to
<target1
>{}, implicit_to
<target2
>{});
76 // And also constexpr across pair types
78 constexpr hana::pair
<int, short> p1(3, 4);
79 constexpr hana::pair
<double, long> p2
= p1
;
80 static_assert(hana::first(p2
) == 3, "");
81 static_assert(hana::second(p2
) == 4, "");
84 // Make sure we don't define the copy constructor when it shouldn't be defined.
86 using Pair1
= hana::pair
<NoCopy
, NoCopy
>;
88 static_assert(!std::is_copy_constructible
<Pair1
>::value
, "");
90 using Pair2
= hana::pair
<NoCopy_nonempty
, NoCopy_nonempty
>;
92 static_assert(!std::is_copy_constructible
<Pair2
>::value
, "");