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/bool.hpp>
7 #include <boost/hana/first.hpp>
8 #include <boost/hana/integral_constant.hpp>
9 #include <boost/hana/pair.hpp>
10 #include <boost/hana/second.hpp>
11 #include <boost/hana/tuple.hpp>
12
13 #include <type_traits>
14 #include <utility>
15 namespace hana = boost::hana;
16
17
18 // In GitHub issue #331, we noticed that `first` and `second` could sometimes
19 // return the wrong member in case of nested pairs. This is due to the way we
20 // inherit from base classes to enable EBO. We also check for `basic_tuple`,
21 // because both are implemented similarly.
22
main()23 int main() {
24 {
25 using Nested = hana::pair<hana::int_<1>, hana::int_<2>>;
26 using Pair = hana::pair<hana::int_<0>, Nested>;
27 Pair pair{};
28
29 auto a = hana::first(pair);
30 static_assert(std::is_same<decltype(a), hana::int_<0>>{}, "");
31
32 auto b = hana::second(pair);
33 static_assert(std::is_same<decltype(b), Nested>{}, "");
34 }
35
36 {
37 using Nested = hana::basic_tuple<hana::int_<1>, hana::int_<2>>;
38 using Tuple = hana::basic_tuple<hana::int_<0>, Nested>;
39 Tuple tuple{};
40
41 auto a = hana::at_c<0>(tuple);
42 static_assert(std::is_same<decltype(a), hana::int_<0>>{}, "");
43
44 auto b = hana::at_c<1>(tuple);
45 static_assert(std::is_same<decltype(b), Nested>{}, "");
46 }
47
48 // Original test case submitted by Vittorio Romeo
49 {
50 hana::pair<hana::int_<1>, hana::bool_<false>> p{};
51 auto copy = hana::make_pair(hana::int_c<0>, p);
52 auto move = hana::make_pair(hana::int_c<0>, std::move(p));
53
54 copy = move; // copy assign
55 copy = std::move(move); // move assign
56 }
57 }
58