diff --git a/include/boost/unordered/detail/foa.hpp b/include/boost/unordered/detail/foa.hpp index 4be574ee..7d8a15c9 100644 --- a/include/boost/unordered/detail/foa.hpp +++ b/include/boost/unordered/detail/foa.hpp @@ -1063,10 +1063,14 @@ public: std::forward_as_tuple(std::forward(args)...)); } - template + template< + typename T, + typename std::enable_if< + std::is_constructible::value>* =nullptr + > BOOST_FORCEINLINE std::pair insert(T&& x) { - return emplace_impl(std::forward(x)); + return emplace_impl(value_from(std::forward(x))); } BOOST_FORCEINLINE std::pair insert(init_type&& x) @@ -1228,12 +1232,42 @@ 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< - class T, + typename T, + typename std::enable_if::value>::type* =nullptr + > + static inline auto value_from(T&& x)->decltype(std::forward(x)) + { + return std::forward(x); + } + + template< + typename T, + typename std::enable_if::value>::type* =nullptr + > + static inline init_type value_from(T&& x) + { + return {std::forward(x)}; + } + + template< + typename T, typename std::enable_if< - has_different_init_type&&( - std::is_same::value||std::is_same::value - )>::type* =nullptr + has_different_init_type&& + is_init_or_value_type::value>::type* =nullptr > static inline auto key_from(const T& x) ->decltype(type_policy::extract(x)) @@ -1247,7 +1281,10 @@ private: return type_policy::extract(x); } - template + template< + typename Key, + typename std::enable_if::value>::type* =nullptr + > static inline const Key& key_from(const Key& x) { return x; @@ -1498,3 +1535,4 @@ private: #undef BOOST_UNORDERED_SSE2 #endif #endif +