mirror of
https://github.com/boostorg/hana.git
synced 2026-01-25 06:12:23 +00:00
46 lines
1.4 KiB
C++
46 lines
1.4 KiB
C++
// Copyright Louis Dionne 2013-2017
|
|
// Distributed under the Boost Software License, Version 1.0.
|
|
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
|
|
|
|
#include <boost/hana/at.hpp>
|
|
#include <boost/hana/first.hpp>
|
|
#include <boost/hana/integral_constant.hpp>
|
|
#include <boost/hana/pair.hpp>
|
|
#include <boost/hana/second.hpp>
|
|
#include <boost/hana/tuple.hpp>
|
|
|
|
#include <type_traits>
|
|
namespace hana = boost::hana;
|
|
|
|
|
|
// In GitHub issue #331, we noticed that `first` and `second` could sometimes
|
|
// return the wrong member in case of nested pairs. This is due to the way we
|
|
// inherit from base classes to enable EBO. We also check for `basic_tuple`,
|
|
// because both are implemented similarly.
|
|
|
|
int main() {
|
|
{
|
|
using Nested = hana::pair<hana::int_<1>, hana::int_<2>>;
|
|
using Pair = hana::pair<hana::int_<0>, Nested>;
|
|
Pair pair{};
|
|
|
|
auto a = hana::first(pair);
|
|
static_assert(std::is_same<decltype(a), hana::int_<0>>{}, "");
|
|
|
|
auto b = hana::second(pair);
|
|
static_assert(std::is_same<decltype(b), Nested>{}, "");
|
|
}
|
|
|
|
{
|
|
using Nested = hana::basic_tuple<hana::int_<1>, hana::int_<2>>;
|
|
using Tuple = hana::basic_tuple<hana::int_<0>, Nested>;
|
|
Tuple tuple{};
|
|
|
|
auto a = hana::at_c<0>(tuple);
|
|
static_assert(std::is_same<decltype(a), hana::int_<0>>{}, "");
|
|
|
|
auto b = hana::at_c<1>(tuple);
|
|
static_assert(std::is_same<decltype(b), Nested>{}, "");
|
|
}
|
|
}
|