mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2024-11-12 21:09:01 +00:00
113 lines
4 KiB
C++
113 lines
4 KiB
C++
/*=============================================================================
|
|
Copyright (c) 2011-2017 Bolero MURAKAMI
|
|
https://github.com/bolero-MURAKAMI/Sprout
|
|
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
=============================================================================*/
|
|
#ifndef SPROUT_INDEX_TUPLE_TUPLE_HPP
|
|
#define SPROUT_INDEX_TUPLE_TUPLE_HPP
|
|
|
|
#include <tuple>
|
|
#include <sprout/config.hpp>
|
|
#include <sprout/workaround/std/cstddef.hpp>
|
|
#include <sprout/index_tuple/integer_sequence.hpp>
|
|
#include <sprout/index_tuple/index_tuple.hpp>
|
|
#include <sprout/utility/pack.hpp>
|
|
#include <sprout/type_traits/integral_constant.hpp>
|
|
|
|
namespace std {
|
|
#if defined(__clang__)
|
|
# pragma clang diagnostic push
|
|
# pragma clang diagnostic ignored "-Wmismatched-tags"
|
|
#endif
|
|
//
|
|
// tuple_size
|
|
//
|
|
template<typename T, T... Is>
|
|
struct tuple_size<sprout::integer_sequence<T, Is...> >
|
|
: public sprout::integral_constant<std::size_t, sizeof...(Is)>
|
|
{};
|
|
//
|
|
// tuple_element
|
|
//
|
|
template<std::size_t I, typename T, T... Is>
|
|
struct tuple_element<I, sprout::integer_sequence<T, Is...> >
|
|
: public sprout::pack_element_c<I, T, Is...>
|
|
{};
|
|
|
|
#if !(SPROUT_USE_TEMPLATE_ALIASES && !defined(SPROUT_WORKAROUND_NO_TEMPLATE_ARGUMENT_DEDUCTION_WITH_ALIASES))
|
|
//
|
|
// tuple_size
|
|
//
|
|
template<sprout::index_t... Indexes>
|
|
struct tuple_size<sprout::index_tuple<Indexes...> >
|
|
: public std::tuple_size<sprout::integer_sequence<sprout::index_t, Indexes...> >
|
|
{};
|
|
//
|
|
// tuple_element
|
|
//
|
|
template<std::size_t I, sprout::index_t... Indexes>
|
|
struct tuple_element<I, sprout::index_tuple<Indexes...> >
|
|
: public std::tuple_element<I, sprout::integer_sequence<sprout::index_t, Indexes...> >
|
|
{};
|
|
|
|
//
|
|
// tuple_size
|
|
//
|
|
template<sprout::uindex_t... Indexes>
|
|
struct tuple_size<sprout::uindex_tuple<Indexes...> >
|
|
: public std::tuple_size<sprout::integer_sequence<sprout::uindex_t, Indexes...> >
|
|
{};
|
|
//
|
|
// tuple_element
|
|
//
|
|
template<std::size_t I, sprout::uindex_t... Indexes>
|
|
struct tuple_element<I, sprout::uindex_tuple<Indexes...> >
|
|
: public std::tuple_element<I, sprout::integer_sequence<sprout::uindex_t, Indexes...> >
|
|
{};
|
|
#endif // #if !(SPROUT_USE_TEMPLATE_ALIASES && !defined(SPROUT_WORKAROUND_NO_TEMPLATE_ARGUMENT_DEDUCTION_WITH_ALIASES))
|
|
|
|
#if defined(__clang__)
|
|
# pragma clang diagnostic pop
|
|
#endif
|
|
} // namespace std
|
|
|
|
namespace sprout {
|
|
//
|
|
// tuple_get
|
|
//
|
|
template<std::size_t I, typename T, T... Is>
|
|
inline SPROUT_CONSTEXPR typename std::tuple_element<I, sprout::integer_sequence<T, Is...> >::type
|
|
tuple_get(sprout::integer_sequence<T, Is...>) SPROUT_NOEXCEPT {
|
|
static_assert(I < sizeof...(Is), "tuple_get: index out of range");
|
|
typedef typename std::tuple_element<I, sprout::integer_sequence<T, Is...> >::type type;
|
|
return type();
|
|
}
|
|
|
|
#if !(SPROUT_USE_TEMPLATE_ALIASES && !defined(SPROUT_WORKAROUND_NO_TEMPLATE_ARGUMENT_DEDUCTION_WITH_ALIASES))
|
|
//
|
|
// tuple_get
|
|
//
|
|
template<std::size_t I, sprout::index_t... Indexes>
|
|
inline SPROUT_CONSTEXPR typename std::tuple_element<I, sprout::index_tuple<Indexes...> >::type
|
|
tuple_get(sprout::index_tuple<Indexes...>) SPROUT_NOEXCEPT {
|
|
static_assert(I < sizeof...(Indexes), "tuple_get: index out of range");
|
|
typedef typename std::tuple_element<I, sprout::index_tuple<Indexes...> >::type type;
|
|
return type();
|
|
}
|
|
|
|
//
|
|
// tuple_get
|
|
//
|
|
template<std::size_t I, sprout::uindex_t... Indexes>
|
|
inline SPROUT_CONSTEXPR typename std::tuple_element<I, sprout::uindex_tuple<Indexes...> >::type
|
|
tuple_get(sprout::uindex_tuple<Indexes...>) SPROUT_NOEXCEPT {
|
|
static_assert(I < sizeof...(Indexes), "tuple_get: index out of range");
|
|
typedef typename std::tuple_element<I, sprout::uindex_tuple<Indexes...> >::type type;
|
|
return type();
|
|
}
|
|
#endif // #if !(SPROUT_USE_TEMPLATE_ALIASES && !defined(SPROUT_WORKAROUND_NO_TEMPLATE_ARGUMENT_DEDUCTION_WITH_ALIASES))
|
|
} // namespace sprout
|
|
|
|
#endif // #ifndef SPROUT_INDEX_TUPLE_TUPLE_HPP
|