From d93875a65e56bf3a3f3642a470116d222c84bcb8 Mon Sep 17 00:00:00 2001 From: joaquintides Date: Thu, 20 Oct 2022 19:48:17 +0200 Subject: [PATCH] refactored value_from and insert overloads --- include/boost/unordered/detail/foa.hpp | 94 +++++++++++--------------- 1 file changed, 40 insertions(+), 54 deletions(-) diff --git a/include/boost/unordered/detail/foa.hpp b/include/boost/unordered/detail/foa.hpp index 3a224714..903d3c78 100644 --- a/include/boost/unordered/detail/foa.hpp +++ b/include/boost/unordered/detail/foa.hpp @@ -1084,6 +1084,43 @@ private: static constexpr bool has_mutable_iterator= !std::is_same::value; + template< + typename T, + typename RawT=typename std::remove_cv< + typename std::remove_reference::type>::type + > + using value_from_return_type=typename std::conditional< + std::is_same::value||std::is_same::value, + T, + typename std::conditional< + std::is_convertible::value, + const init_type, + typename std::conditional< + std::is_convertible::value, + const value_type, + typename std::conditional< + std::is_convertible::value, + const init_type&, + typename std::conditional< + std::is_convertible::value, + const value_type&, + void + >::type + >::type + >::type + >::type + >::type; + + template< + typename T, + typename std::enable_if< + !std::is_void>::value>::type* =nullptr + > + static inline value_from_return_type value_from(T&& x) + { + return std::forward(x); + } + public: using hasher=Hash; using key_equal=Pred; @@ -1269,12 +1306,9 @@ public: std::forward_as_tuple(std::forward(args)...)); } - template< - typename T, - typename std::enable_if< - std::is_constructible::value>* =nullptr - > - BOOST_FORCEINLINE std::pair insert(T&& x) + template + BOOST_FORCEINLINE auto insert(T&& x) + ->decltype(value_from(std::forward(x)),std::pair()) { return emplace_impl(value_from(std::forward(x))); } @@ -1475,54 +1509,6 @@ private: } } - template - using is_init_or_value_type=std::integral_constant< - bool, - std::is_same< - init_type, - typename std::remove_cv::type>::type - >::value|| - std::is_same< - value_type, - typename std::remove_cv::type>::type - >::value - >; - - template< - typename T, - typename std::enable_if::value>::type* =nullptr - > - static inline T&& value_from(T&& x) - { - return std::forward(x); - } - - template< - typename T, - typename Ty=typename std::decay::type, - typename std::enable_if< - !is_init_or_value_type::value&& - std::is_convertible::value - >::type* =nullptr - > - static inline init_type value_from(T&& x) - { - return std::forward(x); - } - - template< - typename T, - typename Ty=typename std::decay::type, - typename std::enable_if< - !is_init_or_value_type::value&& - !std::is_convertible::value - >::type* =nullptr - > - static inline value_type value_from(T&& x) - { - return std::forward(x); - } - template static inline auto key_from(const T& x) ->decltype(type_policy::extract(x))