From b3ce7296daab031eeaba669cc2db4508b96deb0a Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Thu, 14 Apr 2016 22:05:00 +0900 Subject: [PATCH] change tuple access traits --- sprout/tuple/tuple/get.hpp | 57 +++----------------- sprout/tuple/tuple/tuple_access_traits.hpp | 62 +++++++++++++++++++--- 2 files changed, 61 insertions(+), 58 deletions(-) diff --git a/sprout/tuple/tuple/get.hpp b/sprout/tuple/tuple/get.hpp index e5067896..9825a2e7 100644 --- a/sprout/tuple/tuple/get.hpp +++ b/sprout/tuple/tuple/get.hpp @@ -13,7 +13,6 @@ #include #include #include -#include #include #include #include @@ -22,7 +21,6 @@ #include #include #include -#include namespace sprout { namespace tuples { @@ -49,65 +47,24 @@ namespace sprout { using sprout::tuples::tuple_get; } // namespace sprout -namespace sprout_adl { - template - sprout::not_found_via_adl tuple_get(...); -} // namespace sprout_adl - -namespace sprout_tuple_detail { - using sprout_adl::tuple_get; - - template - inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_traits::template lvalue_reference::type - tuple_get(T& t) - SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::tuple_access_traits::template tuple_get(std::declval())) - { - return sprout::tuples::tuple_access_traits::template tuple_get(t); - } - template - inline SPROUT_CONSTEXPR typename std::enable_if< - !std::is_const::value && !std::is_volatile::value && !std::is_reference::value, - typename sprout::tuples::tuple_traits::type>::template rvalue_reference::type - >::type - tuple_get(T&& t) - SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::tuple_access_traits::type>::template tuple_get(std::declval())) - { - return sprout::move(sprout::tuples::tuple_access_traits::template tuple_get(t)); - } - template - inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_traits::template lvalue_reference::type - tuple_get(T const& t) - SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::tuple_access_traits::template tuple_get(std::declval())) - { - return sprout::tuples::tuple_access_traits::template tuple_get(t); - } - - template - inline SPROUT_CONSTEXPR decltype(tuple_get(std::declval())) - call_tuple_get(T&& t) - SPROUT_NOEXCEPT_IF_EXPR(tuple_get(std::declval())) - { - return tuple_get(SPROUT_FORWARD(T, t)); - } -} // namespace sprout_tuple_detail - namespace sprout { namespace tuples { // // get // // effect: - // ADL callable tuple_get(t) -> tuple_get(t) - // otherwise -> sprout::tuples::tuple_access_traits::tuple_get(t) + // sprout::tuples::tuple_access_traits::type>::template tuple_get(t) // [default] - // std::get(t) + // ADL callable tuple_get(t) -> tuple_get(t) + // [default] + // std::get(t) // template - inline SPROUT_CONSTEXPR decltype(sprout_tuple_detail::call_tuple_get(std::declval())) + inline SPROUT_CONSTEXPR decltype(sprout::tuples::tuple_access_traits::type>::template tuple_get(std::declval())) get(T&& t) - SPROUT_NOEXCEPT_IF_EXPR(sprout_tuple_detail::call_tuple_get(std::declval())) + SPROUT_NOEXCEPT_IF_EXPR(sprout::tuples::tuple_access_traits::type>::template tuple_get(std::declval())) { - return sprout_tuple_detail::call_tuple_get(SPROUT_FORWARD(T, t)); + return sprout::tuples::tuple_access_traits::type>::template tuple_get(SPROUT_FORWARD(T, t)); } // diff --git a/sprout/tuple/tuple/tuple_access_traits.hpp b/sprout/tuple/tuple/tuple_access_traits.hpp index c8d15432..44182778 100644 --- a/sprout/tuple/tuple/tuple_access_traits.hpp +++ b/sprout/tuple/tuple/tuple_access_traits.hpp @@ -8,11 +8,57 @@ #ifndef SPROUT_TUPLE_TUPLE_TUPLE_ACCESS_TRAITS_HPP #define SPROUT_TUPLE_TUPLE_TUPLE_ACCESS_TRAITS_HPP +#include +#include #include #include #include +#include #include -#include +#include +#include + +namespace sprout_adl { + template + sprout::not_found_via_adl tuple_get(...); +} // namespace sprout_adl + +namespace sprout_tuple_detail { + using sprout_adl::tuple_get; + + template + inline SPROUT_CONSTEXPR decltype(std::get(std::declval())) + tuple_get(T& t) + SPROUT_NOEXCEPT_IF_EXPR(std::get(std::declval())) + { + return std::get(t); + } + template + inline SPROUT_CONSTEXPR typename std::enable_if< + !std::is_const::value && !std::is_volatile::value && !std::is_reference::value, + decltype(sprout::move(std::get(std::declval()))) + >::type + tuple_get(T&& t) + SPROUT_NOEXCEPT_IF_EXPR(sprout::move(std::get(std::declval()))) + { + return sprout::move(std::get(t)); + } + template + inline SPROUT_CONSTEXPR decltype(std::get(std::declval())) + tuple_get(T const& t) + SPROUT_NOEXCEPT_IF_EXPR(std::get(std::declval())) + { + return std::get(t); + } + + template + inline SPROUT_CONSTEXPR decltype(tuple_get(std::declval())) + call_tuple_get(T&& t) + SPROUT_NOEXCEPT_IF_EXPR(tuple_get(std::declval())) + { + return tuple_get(SPROUT_FORWARD(T, t)); + } +} // namespace sprout_tuple_detail namespace sprout { namespace tuples { @@ -23,26 +69,26 @@ namespace sprout { struct tuple_access_traits { public: template - static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element::type& + static SPROUT_CONSTEXPR typename sprout::tuples::tuple_traits::template lvalue_reference::type tuple_get(Tuple& t) SPROUT_NOEXCEPT { - return std::get(t); + return sprout_tuple_detail::call_tuple_get(t); } template - static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element::type&& + static SPROUT_CONSTEXPR typename sprout::tuples::tuple_traits::template rvalue_reference::type tuple_get(Tuple&& t) SPROUT_NOEXCEPT { - return sprout::move(std::get(t)); + return sprout_tuple_detail::call_tuple_get(sprout::move(t)); } template - static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element::type const& + static SPROUT_CONSTEXPR typename sprout::tuples::tuple_traits::template lvalue_reference::type tuple_get(Tuple const& t) SPROUT_NOEXCEPT { - return std::get(t); + return sprout_tuple_detail::call_tuple_get(t); } }; template struct tuple_access_traits { public: template - static SPROUT_CONSTEXPR typename sprout::tuples::tuple_element::type const& + static SPROUT_CONSTEXPR typename sprout::tuples::tuple_traits::template lvalue_reference::type tuple_get(Tuple const& t) SPROUT_NOEXCEPT { return sprout::tuples::tuple_access_traits::template tuple_get(t); }