mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2024-11-12 21:09:01 +00:00
change tuple access traits
This commit is contained in:
parent
75e164418b
commit
b3ce7296da
2 changed files with 61 additions and 58 deletions
|
@ -13,7 +13,6 @@
|
|||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/utility/move.hpp>
|
||||
#include <sprout/tuple/tuple/tuple.hpp>
|
||||
#include <sprout/tuple/tuple/tuple_size.hpp>
|
||||
#include <sprout/tuple/tuple/tuple_element.hpp>
|
||||
|
@ -22,7 +21,6 @@
|
|||
#include <sprout/type/algorithm/find_index.hpp>
|
||||
#include <sprout/type/algorithm/count.hpp>
|
||||
#include <sprout/type_traits/remove_cvref.hpp>
|
||||
#include <sprout/adl/not_found.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace tuples {
|
||||
|
@ -49,65 +47,24 @@ namespace sprout {
|
|||
using sprout::tuples::tuple_get;
|
||||
} // namespace sprout
|
||||
|
||||
namespace sprout_adl {
|
||||
template<std::size_t I>
|
||||
sprout::not_found_via_adl tuple_get(...);
|
||||
} // namespace sprout_adl
|
||||
|
||||
namespace sprout_tuple_detail {
|
||||
using sprout_adl::tuple_get;
|
||||
|
||||
template<std::size_t I, typename T>
|
||||
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_traits<T>::template lvalue_reference<I>::type
|
||||
tuple_get(T& t)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::tuple_access_traits<T>::template tuple_get<I>(std::declval<T&>()))
|
||||
{
|
||||
return sprout::tuples::tuple_access_traits<T>::template tuple_get<I>(t);
|
||||
}
|
||||
template<std::size_t I, typename T>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
!std::is_const<T>::value && !std::is_volatile<T>::value && !std::is_reference<T>::value,
|
||||
typename sprout::tuples::tuple_traits<typename std::remove_reference<T>::type>::template rvalue_reference<I>::type
|
||||
>::type
|
||||
tuple_get(T&& t)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::tuple_access_traits<typename std::remove_reference<T>::type>::template tuple_get<I>(std::declval<T&&>()))
|
||||
{
|
||||
return sprout::move(sprout::tuples::tuple_access_traits<T>::template tuple_get<I>(t));
|
||||
}
|
||||
template<std::size_t I, typename T>
|
||||
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_traits<T const>::template lvalue_reference<I>::type
|
||||
tuple_get(T const& t)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::tuple_access_traits<T const>::template tuple_get<I>(std::declval<T const&>()))
|
||||
{
|
||||
return sprout::tuples::tuple_access_traits<T const>::template tuple_get<I>(t);
|
||||
}
|
||||
|
||||
template<std::size_t I, typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(tuple_get<I>(std::declval<T>()))
|
||||
call_tuple_get(T&& t)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(tuple_get<I>(std::declval<T>()))
|
||||
{
|
||||
return tuple_get<I>(SPROUT_FORWARD(T, t));
|
||||
}
|
||||
} // namespace sprout_tuple_detail
|
||||
|
||||
namespace sprout {
|
||||
namespace tuples {
|
||||
//
|
||||
// get
|
||||
//
|
||||
// effect:
|
||||
// ADL callable tuple_get<I>(t) -> tuple_get<I>(t)
|
||||
// otherwise -> sprout::tuples::tuple_access_traits<T>::tuple_get<I>(t)
|
||||
// sprout::tuples::tuple_access_traits<typename std::remove_reference<T>::type>::template tuple_get<I>(t)
|
||||
// [default]
|
||||
// std::get<I>(t)
|
||||
// ADL callable tuple_get<I>(t) -> tuple_get<I>(t)
|
||||
// [default]
|
||||
// std::get<I>(t)
|
||||
//
|
||||
template<std::size_t I, typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(sprout_tuple_detail::call_tuple_get<I>(std::declval<T>()))
|
||||
inline SPROUT_CONSTEXPR decltype(sprout::tuples::tuple_access_traits<typename std::remove_reference<T>::type>::template tuple_get<I>(std::declval<T>()))
|
||||
get(T&& t)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout_tuple_detail::call_tuple_get<I>(std::declval<T>()))
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::tuple_access_traits<typename std::remove_reference<T>::type>::template tuple_get<I>(std::declval<T>()))
|
||||
{
|
||||
return sprout_tuple_detail::call_tuple_get<I>(SPROUT_FORWARD(T, t));
|
||||
return sprout::tuples::tuple_access_traits<typename std::remove_reference<T>::type>::template tuple_get<I>(SPROUT_FORWARD(T, t));
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -8,11 +8,57 @@
|
|||
#ifndef SPROUT_TUPLE_TUPLE_TUPLE_ACCESS_TRAITS_HPP
|
||||
#define SPROUT_TUPLE_TUPLE_TUPLE_ACCESS_TRAITS_HPP
|
||||
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <tuple>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/utility/move.hpp>
|
||||
#include <sprout/tuple/tuple/tuple_element.hpp>
|
||||
#include <sprout/tuple/tuple/tuple_traits.hpp>
|
||||
#include <sprout/adl/not_found.hpp>
|
||||
|
||||
namespace sprout_adl {
|
||||
template<std::size_t I>
|
||||
sprout::not_found_via_adl tuple_get(...);
|
||||
} // namespace sprout_adl
|
||||
|
||||
namespace sprout_tuple_detail {
|
||||
using sprout_adl::tuple_get;
|
||||
|
||||
template<std::size_t I, typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(std::get<I>(std::declval<T&>()))
|
||||
tuple_get(T& t)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(std::get<I>(std::declval<T&>()))
|
||||
{
|
||||
return std::get<I>(t);
|
||||
}
|
||||
template<std::size_t I, typename T>
|
||||
inline SPROUT_CONSTEXPR typename std::enable_if<
|
||||
!std::is_const<T>::value && !std::is_volatile<T>::value && !std::is_reference<T>::value,
|
||||
decltype(sprout::move(std::get<I>(std::declval<T&&>())))
|
||||
>::type
|
||||
tuple_get(T&& t)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(sprout::move(std::get<I>(std::declval<T&&>())))
|
||||
{
|
||||
return sprout::move(std::get<I>(t));
|
||||
}
|
||||
template<std::size_t I, typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(std::get<I>(std::declval<T const&>()))
|
||||
tuple_get(T const& t)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(std::get<I>(std::declval<T const&>()))
|
||||
{
|
||||
return std::get<I>(t);
|
||||
}
|
||||
|
||||
template<std::size_t I, typename T>
|
||||
inline SPROUT_CONSTEXPR decltype(tuple_get<I>(std::declval<T>()))
|
||||
call_tuple_get(T&& t)
|
||||
SPROUT_NOEXCEPT_IF_EXPR(tuple_get<I>(std::declval<T>()))
|
||||
{
|
||||
return tuple_get<I>(SPROUT_FORWARD(T, t));
|
||||
}
|
||||
} // namespace sprout_tuple_detail
|
||||
|
||||
namespace sprout {
|
||||
namespace tuples {
|
||||
|
@ -23,26 +69,26 @@ namespace sprout {
|
|||
struct tuple_access_traits {
|
||||
public:
|
||||
template<std::size_t I>
|
||||
static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, Tuple>::type&
|
||||
static SPROUT_CONSTEXPR typename sprout::tuples::tuple_traits<Tuple>::template lvalue_reference<I>::type
|
||||
tuple_get(Tuple& t) SPROUT_NOEXCEPT {
|
||||
return std::get<I>(t);
|
||||
return sprout_tuple_detail::call_tuple_get<I>(t);
|
||||
}
|
||||
template<std::size_t I>
|
||||
static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, Tuple>::type&&
|
||||
static SPROUT_CONSTEXPR typename sprout::tuples::tuple_traits<Tuple>::template rvalue_reference<I>::type
|
||||
tuple_get(Tuple&& t) SPROUT_NOEXCEPT {
|
||||
return sprout::move(std::get<I>(t));
|
||||
return sprout_tuple_detail::call_tuple_get<I>(sprout::move(t));
|
||||
}
|
||||
template<std::size_t I>
|
||||
static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, Tuple>::type const&
|
||||
static SPROUT_CONSTEXPR typename sprout::tuples::tuple_traits<Tuple const>::template lvalue_reference<I>::type
|
||||
tuple_get(Tuple const& t) SPROUT_NOEXCEPT {
|
||||
return std::get<I>(t);
|
||||
return sprout_tuple_detail::call_tuple_get<I>(t);
|
||||
}
|
||||
};
|
||||
template<typename Tuple>
|
||||
struct tuple_access_traits<Tuple const> {
|
||||
public:
|
||||
template<std::size_t I>
|
||||
static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, Tuple>::type const&
|
||||
static SPROUT_CONSTEXPR typename sprout::tuples::tuple_traits<Tuple const>::template lvalue_reference<I>::type
|
||||
tuple_get(Tuple const& t) SPROUT_NOEXCEPT {
|
||||
return sprout::tuples::tuple_access_traits<Tuple>::template tuple_get<I>(t);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue