mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-01-23 20:46:37 +00:00
add tuple_traits
This commit is contained in:
parent
be5fc7df52
commit
f830221c56
4 changed files with 106 additions and 5 deletions
|
@ -20,7 +20,7 @@
|
||||||
#include <sprout/tuple/tuple/ignore.hpp>
|
#include <sprout/tuple/tuple/ignore.hpp>
|
||||||
#include <sprout/tuple/tuple/make_tuple.hpp>
|
#include <sprout/tuple/tuple/make_tuple.hpp>
|
||||||
#include <sprout/tuple/tuple/type_traits.hpp>
|
#include <sprout/tuple/tuple/type_traits.hpp>
|
||||||
#include <sprout/tuple/tuple/tuple_access_traits.hpp>
|
#include <sprout/tuple/tuple/traits.hpp>
|
||||||
#include <sprout/tuple/flexibly_construct.hpp>
|
#include <sprout/tuple/flexibly_construct.hpp>
|
||||||
|
|
||||||
#endif // #ifndef SPROUT_TUPLE_TUPLE_HPP
|
#endif // #ifndef SPROUT_TUPLE_TUPLE_HPP
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include <sprout/tuple/tuple/tuple.hpp>
|
#include <sprout/tuple/tuple/tuple.hpp>
|
||||||
#include <sprout/tuple/tuple/tuple_size.hpp>
|
#include <sprout/tuple/tuple/tuple_size.hpp>
|
||||||
#include <sprout/tuple/tuple/tuple_element.hpp>
|
#include <sprout/tuple/tuple/tuple_element.hpp>
|
||||||
|
#include <sprout/tuple/tuple/tuple_traits.hpp>
|
||||||
#include <sprout/tuple/tuple/tuple_access_traits.hpp>
|
#include <sprout/tuple/tuple/tuple_access_traits.hpp>
|
||||||
#include <sprout/adl/not_found.hpp>
|
#include <sprout/adl/not_found.hpp>
|
||||||
|
|
||||||
|
@ -66,7 +67,7 @@ namespace sprout_tuple_detail {
|
||||||
using sprout_adl::tuple_get;
|
using sprout_adl::tuple_get;
|
||||||
|
|
||||||
template<std::size_t I, typename T>
|
template<std::size_t I, typename T>
|
||||||
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, T>::type&
|
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_traits<T>::template lvalue_reference<I>::type
|
||||||
tuple_get(T& t)
|
tuple_get(T& t)
|
||||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::tuple_access_traits<T>::template tuple_get<I>(std::declval<T&>())))
|
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::tuple_access_traits<T>::template tuple_get<I>(std::declval<T&>())))
|
||||||
{
|
{
|
||||||
|
@ -75,15 +76,15 @@ namespace sprout_tuple_detail {
|
||||||
template<std::size_t I, typename T>
|
template<std::size_t I, typename T>
|
||||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||||
!std::is_const<T>::value && !std::is_volatile<T>::value && !std::is_reference<T>::value,
|
!std::is_const<T>::value && !std::is_volatile<T>::value && !std::is_reference<T>::value,
|
||||||
typename sprout::tuples::tuple_element<I, typename std::remove_reference<T>::type>::type&&
|
typename sprout::tuples::tuple_traits<typename std::remove_reference<T>::type>::template rvalue_reference<I>::type
|
||||||
>::type
|
>::type
|
||||||
tuple_get(T&& t)
|
tuple_get(T&& t)
|
||||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::tuple_access_traits<T>::template tuple_get<I>(std::declval<T&&>())))
|
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::tuple_access_traits<typename std::remove_reference<T>::type>::template tuple_get<I>(std::declval<T&&>())))
|
||||||
{
|
{
|
||||||
return sprout::tuples::tuple_access_traits<T>::template tuple_get<I>(t);
|
return sprout::tuples::tuple_access_traits<T>::template tuple_get<I>(t);
|
||||||
}
|
}
|
||||||
template<std::size_t I, typename T>
|
template<std::size_t I, typename T>
|
||||||
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, T>::type const&
|
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_traits<T const>::template lvalue_reference<I>::type
|
||||||
tuple_get(T const& t)
|
tuple_get(T const& t)
|
||||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::tuple_access_traits<T const>::template tuple_get<I>(std::declval<T const&>())))
|
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::tuples::tuple_access_traits<T const>::template tuple_get<I>(std::declval<T const&>())))
|
||||||
{
|
{
|
||||||
|
|
15
sprout/tuple/tuple/traits.hpp
Normal file
15
sprout/tuple/tuple/traits.hpp
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2011-2014 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_TUPLE_TUPLE_TRAITS_HPP
|
||||||
|
#define SPROUT_TUPLE_TUPLE_TRAITS_HPP
|
||||||
|
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
#include <sprout/tuple/tuple/tuple_traits.hpp>
|
||||||
|
#include <sprout/tuple/tuple/tuple_access_traits.hpp>
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_TUPLE_TUPLE_TRAITS_HPP
|
85
sprout/tuple/tuple/tuple_traits.hpp
Normal file
85
sprout/tuple/tuple/tuple_traits.hpp
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
/*=============================================================================
|
||||||
|
Copyright (c) 2011-2014 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_TUPLE_TUPLE_TUPLE_TRAITS_HPP
|
||||||
|
#define SPROUT_TUPLE_TUPLE_TUPLE_TRAITS_HPP
|
||||||
|
|
||||||
|
#include <tuple>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <sprout/config.hpp>
|
||||||
|
#include <sprout/workaround/std/cstddef.hpp>
|
||||||
|
#include <sprout/tuple/tuple/tuple_size.hpp>
|
||||||
|
#include <sprout/tuple/tuple/tuple_element.hpp>
|
||||||
|
|
||||||
|
namespace sprout {
|
||||||
|
namespace tuples {
|
||||||
|
//
|
||||||
|
// tuple_traits
|
||||||
|
//
|
||||||
|
template<typename Tuple>
|
||||||
|
struct tuple_traits {
|
||||||
|
public:
|
||||||
|
SPROUT_STATIC_CONSTEXPR std::size_t size = sprout::tuples::tuple_size<Tuple>::value;
|
||||||
|
public:
|
||||||
|
template<std::size_t I>
|
||||||
|
struct element
|
||||||
|
: public sprout::tuples::tuple_element<I, Tuple>
|
||||||
|
{};
|
||||||
|
template<std::size_t I>
|
||||||
|
struct lvalue_reference
|
||||||
|
: public std::add_lvalue_reference<typename element<I>::type>
|
||||||
|
{};
|
||||||
|
template<std::size_t I>
|
||||||
|
struct const_lvalue_reference
|
||||||
|
: public std::add_lvalue_reference<typename element<I>::type const>
|
||||||
|
{};
|
||||||
|
template<std::size_t I>
|
||||||
|
struct rvalue_reference
|
||||||
|
: public std::add_rvalue_reference<typename element<I>::type>
|
||||||
|
{};
|
||||||
|
template<std::size_t I>
|
||||||
|
struct const_rvalue_reference
|
||||||
|
: public std::add_rvalue_reference<typename element<I>::type const>
|
||||||
|
{};
|
||||||
|
};
|
||||||
|
template<typename Tuple>
|
||||||
|
SPROUT_CONSTEXPR_OR_CONST std::size_t sprout::tuples::tuple_traits<Tuple>::size;
|
||||||
|
|
||||||
|
template<typename Tuple>
|
||||||
|
struct tuple_traits<Tuple const> {
|
||||||
|
public:
|
||||||
|
SPROUT_STATIC_CONSTEXPR std::size_t size = sprout::tuples::tuple_traits<Tuple>::size;
|
||||||
|
public:
|
||||||
|
template<std::size_t I>
|
||||||
|
struct element
|
||||||
|
: public sprout::tuples::tuple_traits<Tuple>::template element<I>
|
||||||
|
{};
|
||||||
|
template<std::size_t I>
|
||||||
|
struct lvalue_reference
|
||||||
|
: public sprout::tuples::tuple_traits<Tuple>::template const_lvalue_reference<I>
|
||||||
|
{};
|
||||||
|
template<std::size_t I>
|
||||||
|
struct const_lvalue_reference
|
||||||
|
: public sprout::tuples::tuple_traits<Tuple>::template const_lvalue_reference<I>
|
||||||
|
{};
|
||||||
|
template<std::size_t I>
|
||||||
|
struct rvalue_reference
|
||||||
|
: public sprout::tuples::tuple_traits<Tuple>::template const_rvalue_reference<I>
|
||||||
|
{};
|
||||||
|
template<std::size_t I>
|
||||||
|
struct const_rvalue_reference
|
||||||
|
: public sprout::tuples::tuple_traits<Tuple>::template const_rvalue_reference<I>
|
||||||
|
{};
|
||||||
|
};
|
||||||
|
template<typename Tuple>
|
||||||
|
SPROUT_CONSTEXPR_OR_CONST std::size_t sprout::tuples::tuple_traits<Tuple const>::size;
|
||||||
|
} // namespace tuples
|
||||||
|
|
||||||
|
using sprout::tuples::tuple_traits;
|
||||||
|
} // namespace sprout
|
||||||
|
|
||||||
|
#endif // #ifndef SPROUT_TUPLE_TUPLE_TUPLE_TRAITS_HPP
|
Loading…
Reference in a new issue