[libcxx-commits] [libcxx] [libc++] Simplify overload sets where C::iterator == C::const_iterator (PR #66080)

Amirreza Ashouri via libcxx-commits libcxx-commits at lists.llvm.org
Tue Sep 12 05:57:04 PDT 2023


https://github.com/AMP999 created https://github.com/llvm/llvm-project/pull/66080:

No functional change intended, except to speed up overload resolution. The removed non-const overloads always do exactly the same thing as the const overloads, _including_ having the same return type, because for these `set`-like types the `iterator` and `const_iterator` types are identical by design. (And we'll never change this, because that would break existing user code that assumes they're identical.)

>From cbc83e30d345b216a6c3048be95a82d4b19ec6e1 Mon Sep 17 00:00:00 2001
From: Amirreza Ashouri <ar.ashouri999 at gmail.com>
Date: Tue, 12 Sep 2023 16:23:45 +0330
Subject: [PATCH] [libc++] Simplify overload sets where C::iterator ==
 C::const_iterator

No functional change intended, except to speed up overload resolution.
The removed non-const overloads always do exactly the same thing as
the const overloads, _including_ having the same return type, because
for these `set`-like types the `iterator` and `const_iterator` types
are identical by design. (And we'll never change this, because that
would break existing user code that assumes they're identical.)
---
 libcxx/include/set           | 76 ------------------------------------
 libcxx/include/unordered_set | 40 -------------------
 2 files changed, 116 deletions(-)

diff --git a/libcxx/include/set b/libcxx/include/set
index 75be1e13ede511d..70c6cfedb5fa671 100644
--- a/libcxx/include/set
+++ b/libcxx/include/set
@@ -741,24 +741,14 @@ public:
         static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
     }
 
-    _LIBCPP_INLINE_VISIBILITY
-          iterator begin() _NOEXCEPT       {return __tree_.begin();}
     _LIBCPP_INLINE_VISIBILITY
     const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
-    _LIBCPP_INLINE_VISIBILITY
-          iterator end() _NOEXCEPT         {return __tree_.end();}
     _LIBCPP_INLINE_VISIBILITY
     const_iterator end()   const _NOEXCEPT {return __tree_.end();}
 
-    _LIBCPP_INLINE_VISIBILITY
-          reverse_iterator rbegin() _NOEXCEPT
-            {return reverse_iterator(end());}
     _LIBCPP_INLINE_VISIBILITY
     const_reverse_iterator rbegin() const _NOEXCEPT
         {return const_reverse_iterator(end());}
-    _LIBCPP_INLINE_VISIBILITY
-          reverse_iterator rend() _NOEXCEPT
-            {return reverse_iterator(begin());}
     _LIBCPP_INLINE_VISIBILITY
     const_reverse_iterator rend() const _NOEXCEPT
         {return const_reverse_iterator(begin());}
@@ -916,14 +906,8 @@ public:
 
     // set operations:
     _LIBCPP_INLINE_VISIBILITY
-    iterator find(const key_type& __k)             {return __tree_.find(__k);}
-    _LIBCPP_INLINE_VISIBILITY
     const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
 #if _LIBCPP_STD_VER >= 14
-    template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
-    _LIBCPP_INLINE_VISIBILITY
-    iterator
-    find(const _K2& __k)                           {return __tree_.find(__k);}
     template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
     _LIBCPP_INLINE_VISIBILITY
     const_iterator
@@ -950,17 +934,9 @@ public:
 #endif // _LIBCPP_STD_VER >= 20
 
     _LIBCPP_INLINE_VISIBILITY
-    iterator lower_bound(const key_type& __k)
-        {return __tree_.lower_bound(__k);}
-    _LIBCPP_INLINE_VISIBILITY
     const_iterator lower_bound(const key_type& __k) const
         {return __tree_.lower_bound(__k);}
 #if _LIBCPP_STD_VER >= 14
-    template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
-    _LIBCPP_INLINE_VISIBILITY
-    iterator
-    lower_bound(const _K2& __k)       {return __tree_.lower_bound(__k);}
-
     template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
     _LIBCPP_INLINE_VISIBILITY
     const_iterator
@@ -968,16 +944,9 @@ public:
 #endif
 
     _LIBCPP_INLINE_VISIBILITY
-    iterator upper_bound(const key_type& __k)
-        {return __tree_.upper_bound(__k);}
-    _LIBCPP_INLINE_VISIBILITY
     const_iterator upper_bound(const key_type& __k) const
         {return __tree_.upper_bound(__k);}
 #if _LIBCPP_STD_VER >= 14
-    template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
-    _LIBCPP_INLINE_VISIBILITY
-    iterator
-    upper_bound(const _K2& __k)       {return __tree_.upper_bound(__k);}
     template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
     _LIBCPP_INLINE_VISIBILITY
     const_iterator
@@ -985,16 +954,9 @@ public:
 #endif
 
     _LIBCPP_INLINE_VISIBILITY
-    pair<iterator,iterator> equal_range(const key_type& __k)
-        {return __tree_.__equal_range_unique(__k);}
-    _LIBCPP_INLINE_VISIBILITY
     pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
         {return __tree_.__equal_range_unique(__k);}
 #if _LIBCPP_STD_VER >= 14
-    template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator,iterator>
-    equal_range(const _K2& __k)       {return __tree_.__equal_range_multi(__k);}
     template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
     _LIBCPP_INLINE_VISIBILITY
     pair<const_iterator,const_iterator>
@@ -1332,24 +1294,14 @@ public:
         static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
     }
 
-    _LIBCPP_INLINE_VISIBILITY
-          iterator begin() _NOEXCEPT       {return __tree_.begin();}
     _LIBCPP_INLINE_VISIBILITY
     const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
-    _LIBCPP_INLINE_VISIBILITY
-          iterator end() _NOEXCEPT         {return __tree_.end();}
     _LIBCPP_INLINE_VISIBILITY
     const_iterator end()   const _NOEXCEPT {return __tree_.end();}
 
-    _LIBCPP_INLINE_VISIBILITY
-          reverse_iterator rbegin() _NOEXCEPT
-            {return reverse_iterator(end());}
     _LIBCPP_INLINE_VISIBILITY
     const_reverse_iterator rbegin() const _NOEXCEPT
         {return const_reverse_iterator(end());}
-    _LIBCPP_INLINE_VISIBILITY
-          reverse_iterator rend() _NOEXCEPT
-            {return       reverse_iterator(begin());}
     _LIBCPP_INLINE_VISIBILITY
     const_reverse_iterator rend() const _NOEXCEPT
         {return const_reverse_iterator(begin());}
@@ -1507,14 +1459,8 @@ public:
 
     // set operations:
     _LIBCPP_INLINE_VISIBILITY
-    iterator find(const key_type& __k)             {return __tree_.find(__k);}
-    _LIBCPP_INLINE_VISIBILITY
     const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
 #if _LIBCPP_STD_VER >= 14
-    template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
-    _LIBCPP_INLINE_VISIBILITY
-    iterator
-    find(const _K2& __k)                           {return __tree_.find(__k);}
     template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
     _LIBCPP_INLINE_VISIBILITY
     const_iterator
@@ -1541,17 +1487,9 @@ public:
 #endif // _LIBCPP_STD_VER >= 20
 
     _LIBCPP_INLINE_VISIBILITY
-    iterator lower_bound(const key_type& __k)
-        {return __tree_.lower_bound(__k);}
-    _LIBCPP_INLINE_VISIBILITY
     const_iterator lower_bound(const key_type& __k) const
             {return __tree_.lower_bound(__k);}
 #if _LIBCPP_STD_VER >= 14
-    template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
-    _LIBCPP_INLINE_VISIBILITY
-    iterator
-    lower_bound(const _K2& __k)       {return __tree_.lower_bound(__k);}
-
     template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
     _LIBCPP_INLINE_VISIBILITY
     const_iterator
@@ -1559,16 +1497,9 @@ public:
 #endif
 
     _LIBCPP_INLINE_VISIBILITY
-    iterator upper_bound(const key_type& __k)
-            {return __tree_.upper_bound(__k);}
-    _LIBCPP_INLINE_VISIBILITY
     const_iterator upper_bound(const key_type& __k) const
             {return __tree_.upper_bound(__k);}
 #if _LIBCPP_STD_VER >= 14
-    template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
-    _LIBCPP_INLINE_VISIBILITY
-    iterator
-    upper_bound(const _K2& __k)       {return __tree_.upper_bound(__k);}
     template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
     _LIBCPP_INLINE_VISIBILITY
     const_iterator
@@ -1576,16 +1507,9 @@ public:
 #endif
 
     _LIBCPP_INLINE_VISIBILITY
-    pair<iterator,iterator>             equal_range(const key_type& __k)
-            {return __tree_.__equal_range_multi(__k);}
-    _LIBCPP_INLINE_VISIBILITY
     pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
             {return __tree_.__equal_range_multi(__k);}
 #if _LIBCPP_STD_VER >= 14
-    template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
-    _LIBCPP_INLINE_VISIBILITY
-    pair<iterator,iterator>
-    equal_range(const _K2& __k)       {return __tree_.__equal_range_multi(__k);}
     template <typename _K2, enable_if_t<__is_transparent<_Compare, _K2>::value, int> = 0>
     _LIBCPP_INLINE_VISIBILITY
     pair<const_iterator,const_iterator>
diff --git a/libcxx/include/unordered_set b/libcxx/include/unordered_set
index 5e47f12446ff936..a38cc8940bbe29c 100644
--- a/libcxx/include/unordered_set
+++ b/libcxx/include/unordered_set
@@ -740,10 +740,6 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     size_type max_size() const _NOEXCEPT {return __table_.max_size();}
 
-    _LIBCPP_INLINE_VISIBILITY
-    iterator       begin() _NOEXCEPT        {return __table_.begin();}
-    _LIBCPP_INLINE_VISIBILITY
-    iterator       end() _NOEXCEPT          {return __table_.end();}
     _LIBCPP_INLINE_VISIBILITY
     const_iterator begin()  const _NOEXCEPT {return __table_.begin();}
     _LIBCPP_INLINE_VISIBILITY
@@ -880,14 +876,9 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     key_equal key_eq() const {return __table_.key_eq();}
 
-    _LIBCPP_INLINE_VISIBILITY
-    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 >= 20
-    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
-    _LIBCPP_INLINE_VISIBILITY
-    iterator       find(const _K2& __k)            {return __table_.find(__k);}
     template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
     _LIBCPP_INLINE_VISIBILITY
     const_iterator find(const _K2& __k) const      {return __table_.find(__k);}
@@ -911,18 +902,11 @@ public:
 #endif // _LIBCPP_STD_VER >= 20
 
     _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, iterator>             equal_range(const key_type& __k)
-        {return __table_.__equal_range_unique(__k);}
-    _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 >= 20
     template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
     _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, iterator>             equal_range(const _K2& __k)
-        {return __table_.__equal_range_unique(__k);}
-    template <class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
-    _LIBCPP_INLINE_VISIBILITY
     pair<const_iterator, const_iterator> equal_range(const _K2& __k) const
         {return __table_.__equal_range_unique(__k);}
 #endif // _LIBCPP_STD_VER >= 20
@@ -937,10 +921,6 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
 
-    _LIBCPP_INLINE_VISIBILITY
-    local_iterator       begin(size_type __n)        {return __table_.begin(__n);}
-    _LIBCPP_INLINE_VISIBILITY
-    local_iterator       end(size_type __n)          {return __table_.end(__n);}
     _LIBCPP_INLINE_VISIBILITY
     const_local_iterator begin(size_type __n) const  {return __table_.cbegin(__n);}
     _LIBCPP_INLINE_VISIBILITY
@@ -1429,10 +1409,6 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     size_type max_size() const _NOEXCEPT {return __table_.max_size();}
 
-    _LIBCPP_INLINE_VISIBILITY
-    iterator       begin() _NOEXCEPT        {return __table_.begin();}
-    _LIBCPP_INLINE_VISIBILITY
-    iterator       end() _NOEXCEPT          {return __table_.end();}
     _LIBCPP_INLINE_VISIBILITY
     const_iterator begin()  const _NOEXCEPT {return __table_.begin();}
     _LIBCPP_INLINE_VISIBILITY
@@ -1566,14 +1542,9 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     key_equal key_eq() const {return __table_.key_eq();}
 
-    _LIBCPP_INLINE_VISIBILITY
-    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 >= 20
-    template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
-    _LIBCPP_INLINE_VISIBILITY
-    iterator       find(const _K2& __k)            {return __table_.find(__k);}
     template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
     _LIBCPP_INLINE_VISIBILITY
     const_iterator find(const _K2& __k) const      {return __table_.find(__k);}
@@ -1597,18 +1568,11 @@ public:
 #endif // _LIBCPP_STD_VER >= 20
 
     _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, iterator>             equal_range(const key_type& __k)
-        {return __table_.__equal_range_multi(__k);}
-    _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 >= 20
     template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
     _LIBCPP_INLINE_VISIBILITY
-    pair<iterator, iterator>             equal_range(const _K2& __k)
-        {return __table_.__equal_range_multi(__k);}
-    template<class _K2, enable_if_t<__is_transparent<hasher, _K2>::value && __is_transparent<key_equal, _K2>::value>* = nullptr>
-    _LIBCPP_INLINE_VISIBILITY
     pair<const_iterator, const_iterator> equal_range(const _K2& __k) const
         {return __table_.__equal_range_multi(__k);}
 #endif // _LIBCPP_STD_VER >= 20
@@ -1623,10 +1587,6 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
 
-    _LIBCPP_INLINE_VISIBILITY
-    local_iterator       begin(size_type __n)        {return __table_.begin(__n);}
-    _LIBCPP_INLINE_VISIBILITY
-    local_iterator       end(size_type __n)          {return __table_.end(__n);}
     _LIBCPP_INLINE_VISIBILITY
     const_local_iterator begin(size_type __n) const  {return __table_.cbegin(__n);}
     _LIBCPP_INLINE_VISIBILITY



More information about the libcxx-commits mailing list