SFINAED out third key_from overload and fixed insert accepted arg types

This commit is contained in:
joaquintides
2022-10-06 20:02:03 +02:00
parent 6b1379a992
commit c57470e0d3

View File

@ -1063,10 +1063,14 @@ public:
std::forward_as_tuple(std::forward<Args>(args)...)); std::forward_as_tuple(std::forward<Args>(args)...));
} }
template<typename T> template<
typename T,
typename std::enable_if<
std::is_constructible<value_type,T&&>::value>* =nullptr
>
BOOST_FORCEINLINE std::pair<iterator,bool> insert(T&& x) BOOST_FORCEINLINE std::pair<iterator,bool> insert(T&& x)
{ {
return emplace_impl(std::forward<T>(x)); return emplace_impl(value_from(std::forward<T>(x)));
} }
BOOST_FORCEINLINE std::pair<iterator,bool> insert(init_type&& x) BOOST_FORCEINLINE std::pair<iterator,bool> insert(init_type&& x)
@ -1228,12 +1232,42 @@ private:
} }
} }
template<typename T>
using is_init_or_value_type=std::integral_constant<
bool,
std::is_same<
init_type,
typename std::remove_cv<typename std::remove_reference<T>::type>::type
>::value||
std::is_same<
value_type,
typename std::remove_cv<typename std::remove_reference<T>::type>::type
>::value
>;
template< template<
class T, typename T,
typename std::enable_if<is_init_or_value_type<T>::value>::type* =nullptr
>
static inline auto value_from(T&& x)->decltype(std::forward<T>(x))
{
return std::forward<T>(x);
}
template<
typename T,
typename std::enable_if<!is_init_or_value_type<T>::value>::type* =nullptr
>
static inline init_type value_from(T&& x)
{
return {std::forward<T>(x)};
}
template<
typename T,
typename std::enable_if< typename std::enable_if<
has_different_init_type&&( has_different_init_type&&
std::is_same<T,init_type>::value||std::is_same<T,moved_type>::value is_init_or_value_type<T>::value>::type* =nullptr
)>::type* =nullptr
> >
static inline auto key_from(const T& x) static inline auto key_from(const T& x)
->decltype(type_policy::extract(x)) ->decltype(type_policy::extract(x))
@ -1247,7 +1281,10 @@ private:
return type_policy::extract(x); return type_policy::extract(x);
} }
template<typename Key> template<
typename Key,
typename std::enable_if<!is_init_or_value_type<Key>::value>::type* =nullptr
>
static inline const Key& key_from(const Key& x) static inline const Key& key_from(const Key& x)
{ {
return x; return x;
@ -1498,3 +1535,4 @@ private:
#undef BOOST_UNORDERED_SSE2 #undef BOOST_UNORDERED_SSE2
#endif #endif
#endif #endif