aboutsummaryrefslogtreecommitdiff
path: root/libcxx/include/unordered_set
diff options
context:
space:
mode:
Diffstat (limited to 'libcxx/include/unordered_set')
-rw-r--r--libcxx/include/unordered_set160
1 files changed, 123 insertions, 37 deletions
diff --git a/libcxx/include/unordered_set b/libcxx/include/unordered_set
index 6c4ad938006f..80f460d7edaa 100644
--- a/libcxx/include/unordered_set
+++ b/libcxx/include/unordered_set
@@ -145,10 +145,22 @@ public:
iterator find(const key_type& k);
const_iterator find(const key_type& k) const;
+ template<typename K>
+ iterator find(const K& x); // C++20
+ template<typename K>
+ const_iterator find(const K& x) const; // C++20
size_type count(const key_type& k) const;
+ template<typename K>
+ size_type count(const K& k) const; // C++20
bool contains(const key_type& k) const; // C++20
+ template<typename K>
+ bool contains(const K& k) const; // C++20
pair<iterator, iterator> equal_range(const key_type& k);
pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
+ template<typename K>
+ pair<iterator, iterator> equal_range(const K& k); // C++20
+ template<typename K>
+ pair<const_iterator, const_iterator> equal_range(const K& k) const; // C++20
size_type bucket_count() const noexcept;
size_type max_bucket_count() const noexcept;
@@ -310,10 +322,22 @@ public:
iterator find(const key_type& k);
const_iterator find(const key_type& k) const;
+ template<typename K>
+ iterator find(const K& x); // C++20
+ template<typename K>
+ const_iterator find(const K& x) const; // C++20
size_type count(const key_type& k) const;
+ template<typename K>
+ size_type count(const K& k) const; // C++20
bool contains(const key_type& k) const; // C++20
+ template<typename K>
+ bool contains(const K& k) const; // C++20
pair<iterator, iterator> equal_range(const key_type& k);
pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
+ template<typename K>
+ pair<iterator, iterator> equal_range(const K& k); // C++20
+ template<typename K>
+ pair<const_iterator, const_iterator> equal_range(const K& k) const; // C++20
size_type bucket_count() const noexcept;
size_type max_bucket_count() const noexcept;
@@ -425,7 +449,7 @@ public:
unordered_set()
_NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
}
@@ -539,7 +563,7 @@ public:
{return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
iterator emplace_hint(const_iterator __p, _Args&&... __args)
{
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
@@ -556,7 +580,7 @@ public:
pair<iterator, bool> insert(value_type&& __x)
{return __table_.__insert_unique(_VSTD::move(__x));}
_LIBCPP_INLINE_VISIBILITY
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
iterator insert(const_iterator __p, value_type&& __x)
{
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
@@ -577,7 +601,7 @@ public:
{return __table_.__insert_unique(__x);}
_LIBCPP_INLINE_VISIBILITY
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
iterator insert(const_iterator __p, const value_type& __x)
{
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
@@ -679,11 +703,32 @@ public:
iterator find(const key_type& __k) {return __table_.find(__k);}
_LIBCPP_INLINE_VISIBILITY
const_iterator find(const key_type& __k) const {return __table_.find(__k);}
+ #if _LIBCPP_STD_VER > 17
+ template <typename _K2>
+ _LIBCPP_INLINE_VISIBILITY
+ _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, iterator>
+ find(const _K2& __k) {return __table_.find(__k);}
+ template <typename _K2>
+ _LIBCPP_INLINE_VISIBILITY
+ _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, const_iterator>
+ find(const _K2& __k) const {return __table_.find(__k);}
+ #endif // _LIBCPP_STD_VER > 17
_LIBCPP_INLINE_VISIBILITY
size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
#if _LIBCPP_STD_VER > 17
+ template <typename _K2>
+ _LIBCPP_INLINE_VISIBILITY
+ _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, size_type>
+ count(const _K2& __k) const {return __table_.__count_unique(__k);}
+ #endif // _LIBCPP_STD_VER > 17
+ #if _LIBCPP_STD_VER > 17
_LIBCPP_INLINE_VISIBILITY
bool contains(const key_type& __k) const {return find(__k) != end();}
+
+ template <typename _K2>
+ _LIBCPP_INLINE_VISIBILITY
+ _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, bool>
+ contains(const _K2& __k) const {return find(__k) != end();}
#endif // _LIBCPP_STD_VER > 17
_LIBCPP_INLINE_VISIBILITY
pair<iterator, iterator> equal_range(const key_type& __k)
@@ -691,6 +736,16 @@ public:
_LIBCPP_INLINE_VISIBILITY
pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
{return __table_.__equal_range_unique(__k);}
+ #if _LIBCPP_STD_VER > 17
+ template <typename _K2>
+ _LIBCPP_INLINE_VISIBILITY
+ _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, pair<iterator, iterator>>
+ equal_range(const _K2& __k) {return __table_.__equal_range_unique(__k);}
+ template <typename _K2>
+ _LIBCPP_INLINE_VISIBILITY
+ _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, pair<const_iterator, const_iterator>>
+ equal_range(const _K2& __k) const {return __table_.__equal_range_unique(__k);}
+ #endif // _LIBCPP_STD_VER > 17
_LIBCPP_INLINE_VISIBILITY
size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
@@ -726,7 +781,7 @@ public:
_LIBCPP_INLINE_VISIBILITY
void reserve(size_type __n) {__table_.reserve(__n);}
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
bool __dereferenceable(const const_iterator* __i) const
{return __table_.__dereferenceable(__i);}
@@ -737,7 +792,7 @@ public:
bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
{return __table_.__addable(__i, __n);}
-#endif // _LIBCPP_DEBUG_LEVEL >= 2
+#endif // _LIBCPP_DEBUG_LEVEL == 2
};
@@ -802,7 +857,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
const hasher& __hf, const key_equal& __eql)
: __table_(__hf, __eql)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
@@ -813,7 +868,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
: __table_(__hf, __eql, __a)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
@@ -824,7 +879,7 @@ template <class _InputIterator>
unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
_InputIterator __first, _InputIterator __last)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
insert(__first, __last);
@@ -837,7 +892,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
const hasher& __hf, const key_equal& __eql)
: __table_(__hf, __eql)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
@@ -851,7 +906,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
: __table_(__hf, __eql, __a)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
@@ -864,7 +919,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
const allocator_type& __a)
: __table_(__a)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
}
@@ -874,7 +929,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
const unordered_set& __u)
: __table_(__u.__table_)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__u.bucket_count());
@@ -886,7 +941,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
const unordered_set& __u, const allocator_type& __a)
: __table_(__u.__table_, __a)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__u.bucket_count());
@@ -902,7 +957,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
_NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
: __table_(_VSTD::move(__u.__table_))
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
__get_db()->swap(this, &__u);
#endif
@@ -913,7 +968,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
unordered_set&& __u, const allocator_type& __a)
: __table_(_VSTD::move(__u.__table_), __a)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
if (__a != __u.get_allocator())
@@ -922,7 +977,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
while (__u.size() != 0)
__table_.__insert_unique(_VSTD::move(__u.__table_.remove(__i++)->__value_));
}
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
else
__get_db()->swap(this, &__u);
#endif
@@ -932,7 +987,7 @@ template <class _Value, class _Hash, class _Pred, class _Alloc>
unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
initializer_list<value_type> __il)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
insert(__il.begin(), __il.end());
@@ -944,7 +999,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
const key_equal& __eql)
: __table_(__hf, __eql)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
@@ -957,7 +1012,7 @@ unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
const key_equal& __eql, const allocator_type& __a)
: __table_(__hf, __eql, __a)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
@@ -1091,7 +1146,7 @@ public:
unordered_multiset()
_NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
}
@@ -1314,11 +1369,32 @@ public:
iterator find(const key_type& __k) {return __table_.find(__k);}
_LIBCPP_INLINE_VISIBILITY
const_iterator find(const key_type& __k) const {return __table_.find(__k);}
+ #if _LIBCPP_STD_VER > 17
+ template <typename _K2>
+ _LIBCPP_INLINE_VISIBILITY
+ _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, iterator>
+ find(const _K2& __k) {return __table_.find(__k);}
+ template <typename _K2>
+ _LIBCPP_INLINE_VISIBILITY
+ _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, const_iterator>
+ find(const _K2& __k) const {return __table_.find(__k);}
+ #endif // _LIBCPP_STD_VER > 17
_LIBCPP_INLINE_VISIBILITY
size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
#if _LIBCPP_STD_VER > 17
+ template <typename _K2>
+ _LIBCPP_INLINE_VISIBILITY
+ _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, size_type>
+ count(const _K2& __k) const {return __table_.__count_multi(__k);}
+ #endif // _LIBCPP_STD_VER > 17
+ #if _LIBCPP_STD_VER > 17
_LIBCPP_INLINE_VISIBILITY
bool contains(const key_type& __k) const {return find(__k) != end();}
+
+ template <typename _K2>
+ _LIBCPP_INLINE_VISIBILITY
+ _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, bool>
+ contains(const _K2& __k) const {return find(__k) != end();}
#endif // _LIBCPP_STD_VER > 17
_LIBCPP_INLINE_VISIBILITY
pair<iterator, iterator> equal_range(const key_type& __k)
@@ -1326,6 +1402,16 @@ public:
_LIBCPP_INLINE_VISIBILITY
pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
{return __table_.__equal_range_multi(__k);}
+ #if _LIBCPP_STD_VER > 17
+ template <typename _K2>
+ _LIBCPP_INLINE_VISIBILITY
+ _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, pair<iterator, iterator>>
+ equal_range(const _K2& __k) {return __table_.__equal_range_multi(__k);}
+ template <typename _K2>
+ _LIBCPP_INLINE_VISIBILITY
+ _EnableIf<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value, pair<const_iterator, const_iterator>>
+ equal_range(const _K2& __k) const {return __table_.__equal_range_multi(__k);}
+ #endif // _LIBCPP_STD_VER > 17
_LIBCPP_INLINE_VISIBILITY
size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
@@ -1361,7 +1447,7 @@ public:
_LIBCPP_INLINE_VISIBILITY
void reserve(size_type __n) {__table_.reserve(__n);}
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
bool __dereferenceable(const const_iterator* __i) const
{return __table_.__dereferenceable(__i);}
@@ -1372,7 +1458,7 @@ public:
bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
{return __table_.__addable(__i, __n);}
-#endif // _LIBCPP_DEBUG_LEVEL >= 2
+#endif // _LIBCPP_DEBUG_LEVEL == 2
};
@@ -1435,7 +1521,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
size_type __n, const hasher& __hf, const key_equal& __eql)
: __table_(__hf, __eql)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
@@ -1447,7 +1533,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
const allocator_type& __a)
: __table_(__hf, __eql, __a)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
@@ -1458,7 +1544,7 @@ template <class _InputIterator>
unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
_InputIterator __first, _InputIterator __last)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
insert(__first, __last);
@@ -1471,7 +1557,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
const hasher& __hf, const key_equal& __eql)
: __table_(__hf, __eql)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
@@ -1485,7 +1571,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
: __table_(__hf, __eql, __a)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
@@ -1498,7 +1584,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
const allocator_type& __a)
: __table_(__a)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
}
@@ -1508,7 +1594,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
const unordered_multiset& __u)
: __table_(__u.__table_)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__u.bucket_count());
@@ -1520,7 +1606,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
const unordered_multiset& __u, const allocator_type& __a)
: __table_(__u.__table_, __a)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__u.bucket_count());
@@ -1536,7 +1622,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
_NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
: __table_(_VSTD::move(__u.__table_))
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
__get_db()->swap(this, &__u);
#endif
@@ -1547,7 +1633,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
unordered_multiset&& __u, const allocator_type& __a)
: __table_(_VSTD::move(__u.__table_), __a)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
if (__a != __u.get_allocator())
@@ -1556,7 +1642,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
while (__u.size() != 0)
__table_.__insert_multi(_VSTD::move(__u.__table_.remove(__i++)->__value_));
}
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
else
__get_db()->swap(this, &__u);
#endif
@@ -1566,7 +1652,7 @@ template <class _Value, class _Hash, class _Pred, class _Alloc>
unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
initializer_list<value_type> __il)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
insert(__il.begin(), __il.end());
@@ -1578,7 +1664,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
const key_equal& __eql)
: __table_(__hf, __eql)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
@@ -1591,7 +1677,7 @@ unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
const key_equal& __eql, const allocator_type& __a)
: __table_(__hf, __eql, __a)
{
-#if _LIBCPP_DEBUG_LEVEL >= 2
+#if _LIBCPP_DEBUG_LEVEL == 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);