Imported Upstream version 1.64.0
[platform/upstream/boost.git] / libs / hana / test / issues / github_331.cpp
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/first.hpp>
7 #include <boost/hana/integral_constant.hpp>
8 #include <boost/hana/pair.hpp>
9 #include <boost/hana/second.hpp>
10 #include <boost/hana/tuple.hpp>
11
12 #include <type_traits>
13 namespace hana = boost::hana;
14
15
16 // In GitHub issue #331, we noticed that `first` and `second` could sometimes
17 // return the wrong member in case of nested pairs. This is due to the way we
18 // inherit from base classes to enable EBO. We also check for `basic_tuple`,
19 // because both are implemented similarly.
20
21 int main() {
22     {
23         using Nested = hana::pair<hana::int_<1>, hana::int_<2>>;
24         using Pair = hana::pair<hana::int_<0>, Nested>;
25         Pair pair{};
26
27         auto a = hana::first(pair);
28         static_assert(std::is_same<decltype(a), hana::int_<0>>{}, "");
29
30         auto b = hana::second(pair);
31         static_assert(std::is_same<decltype(b), Nested>{}, "");
32     }
33
34     {
35         using Nested = hana::basic_tuple<hana::int_<1>, hana::int_<2>>;
36         using Tuple = hana::basic_tuple<hana::int_<0>, Nested>;
37         Tuple tuple{};
38
39         auto a = hana::at_c<0>(tuple);
40         static_assert(std::is_same<decltype(a), hana::int_<0>>{}, "");
41
42         auto b = hana::at_c<1>(tuple);
43         static_assert(std::is_same<decltype(b), Nested>{}, "");
44     }
45 }