From e5637554d18fd8ccaff1e93c51397d8bbee0b9e9 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Thu, 14 Apr 2016 23:16:21 +0900 Subject: [PATCH] change addressof traits --- sprout/functional/hash/to_hash.hpp | 5 +- sprout/memory/addressof.hpp | 90 +++++++++++----------- sprout/tuple/tuple/tuple_access_traits.hpp | 22 +++--- 3 files changed, 56 insertions(+), 61 deletions(-) diff --git a/sprout/functional/hash/to_hash.hpp b/sprout/functional/hash/to_hash.hpp index 659b1da6..dccf8928 100644 --- a/sprout/functional/hash/to_hash.hpp +++ b/sprout/functional/hash/to_hash.hpp @@ -8,6 +8,7 @@ #ifndef SPROUT_FUNCTIONAL_HASH_TO_HASH_HPP #define SPROUT_FUNCTIONAL_HASH_TO_HASH_HPP +#include #include #include #include @@ -17,7 +18,7 @@ namespace sprout { // to_hash // // effect: - // sprout::hash_value_traits::hash_value(v) + // sprout::hash_value_traits::type>::hash_value(v) // [default] // ADL callable hash_value(v) -> hash_value(v) // [default] @@ -27,7 +28,7 @@ namespace sprout { template inline SPROUT_CONSTEXPR std::size_t to_hash(T&& v) { - return sprout::hash_value_traits::hash_value(v); + return sprout::hash_value_traits::type>::hash_value(v); } } // namespace sprout diff --git a/sprout/memory/addressof.hpp b/sprout/memory/addressof.hpp index 314f635c..d0e5f0e8 100644 --- a/sprout/memory/addressof.hpp +++ b/sprout/memory/addressof.hpp @@ -16,6 +16,10 @@ #include #include +namespace sprout_adl { + sprout::not_found_via_adl get_addressof(...); +} // namespace sprout_adl + namespace sprout { namespace detail { struct address_op_helper {}; @@ -72,35 +76,48 @@ namespace sprout { > {}; - template::value> - struct addressof_traits_default; template - struct addressof_traits_default { - public: - template - static U* - get_addressof(U& t) SPROUT_NOEXCEPT { - return std::addressof(t); - } - }; + inline SPROUT_CONSTEXPR typename std::enable_if< + sprout::detail::has_address_op::value, + T* + >::type + get_addressof_impl(T& t) SPROUT_NOEXCEPT { + return std::addressof(t); + } template - struct addressof_traits_default { - public: - template - static SPROUT_CONSTEXPR U* - get_addressof(U& t) SPROUT_NOEXCEPT { - return &t; - } - }; + inline SPROUT_CONSTEXPR typename std::enable_if< + !sprout::detail::has_address_op::value, + T* + >::type + get_addressof_impl(T& t) SPROUT_NOEXCEPT { + return &t; + } } // namespace detail +} // namespace sprout +namespace sprout_addressof_detail { + template + inline SPROUT_CONSTEXPR T* + get_addressof(T& t) SPROUT_NOEXCEPT { + return sprout::detail::get_addressof_impl(t); + } +} // namespace sprout_addressof_detail + +namespace sprout { // // address_traits // template - struct address_traits - : public sprout::detail::addressof_traits_default - {}; + struct address_traits { + public: + template + static SPROUT_CONSTEXPR U* + get_addressof(U& t) SPROUT_NOEXCEPT { + using sprout_addressof_detail::get_addressof; + using sprout_adl::get_addressof; + return get_addressof(t); + } + }; template struct address_traits : public sprout::address_traits @@ -115,41 +132,22 @@ namespace sprout { {}; } // namespace sprout -namespace sprout_adl { - sprout::not_found_via_adl get_addressof(...); -} // namespace sprout_adl - -namespace sprout_addressof_detail { - template - inline SPROUT_CONSTEXPR T* - get_addressof(T& t) SPROUT_NOEXCEPT { - return sprout::address_traits::get_addressof(t); - } - - template - inline SPROUT_CONSTEXPR T* - call_get_addressof(T& t) SPROUT_NOEXCEPT { - using sprout_adl::get_addressof; - using sprout_addressof_detail::get_addressof; - return get_addressof(t); - } -} // namespace sprout_addressof_detail - namespace sprout { // // addressof // // effect: - // ADL callable get_addressof(t) -> get_addressof(t) - // otherwise -> sprout::address_traits::get_addressof(t) + // sprout::address_traits::get_addressof(t) // [default] - // no overloaded operator&() -> &t - // otherwise -> std::addressof(t) + // ADL callable get_addressof(t) -> get_addressof(t) + // [default] + // no overloaded operator&() -> &t + // otherwise -> std::addressof(t) // template inline SPROUT_CONSTEXPR T* addressof(T& t) SPROUT_NOEXCEPT { - return sprout_addressof_detail::call_get_addressof(t); + return sprout::address_traits::get_addressof(t); } } // namespace sprout diff --git a/sprout/tuple/tuple/tuple_access_traits.hpp b/sprout/tuple/tuple/tuple_access_traits.hpp index 44182778..925698f1 100644 --- a/sprout/tuple/tuple/tuple_access_traits.hpp +++ b/sprout/tuple/tuple/tuple_access_traits.hpp @@ -24,8 +24,6 @@ namespace sprout_adl { } // 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) @@ -50,14 +48,6 @@ namespace sprout_tuple_detail { { 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 { @@ -71,17 +61,23 @@ namespace sprout { template static SPROUT_CONSTEXPR typename sprout::tuples::tuple_traits::template lvalue_reference::type tuple_get(Tuple& t) SPROUT_NOEXCEPT { - return sprout_tuple_detail::call_tuple_get(t); + using sprout_tuple_detail::tuple_get; + using sprout_adl::tuple_get; + return tuple_get(t); } template static SPROUT_CONSTEXPR typename sprout::tuples::tuple_traits::template rvalue_reference::type tuple_get(Tuple&& t) SPROUT_NOEXCEPT { - return sprout_tuple_detail::call_tuple_get(sprout::move(t)); + using sprout_tuple_detail::tuple_get; + using sprout_adl::tuple_get; + return tuple_get(sprout::move(t)); } template static SPROUT_CONSTEXPR typename sprout::tuples::tuple_traits::template lvalue_reference::type tuple_get(Tuple const& t) SPROUT_NOEXCEPT { - return sprout_tuple_detail::call_tuple_get(t); + using sprout_tuple_detail::tuple_get; + using sprout_adl::tuple_get; + return tuple_get(t); } }; template