Add SFINAE to transparent count() overload in unordered_map

This commit is contained in:
LeonineKing1199
2021-11-22 11:16:04 -08:00
parent f41b3e8295
commit 59db6cf788
2 changed files with 29 additions and 4 deletions

View File

@ -40,6 +40,7 @@
#include <boost/type_traits/is_nothrow_move_constructible.hpp>
#include <boost/type_traits/is_nothrow_swappable.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/make_void.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <boost/unordered/detail/fwd.hpp>
#include <boost/utility/addressof.hpp>
@ -722,6 +723,22 @@ namespace boost {
#endif
////////////////////////////////////////////////////////////////////////////
// Type checkers used for the transparent member functions added by C++20 and up
template <class>
struct make_dependent : public true_type {};
template <class, class = void> struct is_transparent : public false_type
{
};
template <class T>
struct is_transparent<T,
typename boost::make_void<typename T::is_transparent>::type> : public true_type
{
};
////////////////////////////////////////////////////////////////////////////
// Explicitly call a destructor

View File

@ -757,7 +757,12 @@ namespace boost {
size_type count(const key_type&) const;
template <class TransparentKey> size_type count(const TransparentKey&) const;
template <class Key>
typename boost::enable_if_c<detail::make_dependent<Key>::value &&
detail::is_transparent<H>::value &&
detail::is_transparent<P>::value,
size_type>::type
count(const Key&) const;
std::pair<iterator, iterator> equal_range(const key_type&);
std::pair<const_iterator, const_iterator> equal_range(
@ -1840,9 +1845,12 @@ namespace boost {
}
template <class K, class T, class H, class P, class A>
template <class TransparentKey>
typename unordered_map<K, T, H, P, A>::size_type
unordered_map<K, T, H, P, A>::count(const TransparentKey& k) const
template <class Key>
typename boost::enable_if_c<detail::make_dependent<Key>::value &&
detail::is_transparent<H>::value &&
detail::is_transparent<P>::value,
typename unordered_map<K, T, H, P, A>::size_type>::type
unordered_map<K, T, H, P, A>::count(const Key& k) const
{
std::size_t const key_hash =
table::policy::apply_hash(this->hash_function(), k);