Thank you.

On 2/10/26 7:14 PM, Jonathan Wakely wrote:
On Tue, 10 Feb 2026 at 23:14, Nathan Myers <[email protected]> wrote:

Implement the debug versions of new overloads from P2077.

Also, make existing unordered_set<>::erase perform the same
bucket check as erase on unordered_multimap.
...
+# ifdef __glibcxx_heterogeneous_container_erasure
+      // Note that for some types _Kt this may erase more than
+      // one element, such as if _Kt::operator< checks only part
+      // of the key.
+      template <__heterogeneous_tree_key<map> _Kt>
+       size_type
+       erase(_Kt&& __x)
+       {
+         auto __victims = _Base::equal_range<_Kt>(__x);
+         size_type __count = 0;
+         for (auto __victim = __victims.first; __victim != __victims.second;)
+           {
+             this->_M_invalidate_if(_Equal(__victim));
+             _Base::erase(__victim++);
+             ++__count;
+           }

Would it be more efficient to do one call to:
_Base::erase(__victims.first, __victims.second)
so that the tree doesn't keep rebalancing?

Like

  for (auto __victim = __victims.first; __victim != __victims.second;)
    {
       this->_M_invalidate_if(_Equal(__victim));
       ++__count;
    }
  _Base::erase(__victims.first, victims.second);

? And do it in the existing overloads, too, and in multimap,
set, and multiset?

+         return __count;
+       }
+# endif
...
       size_type
        erase(const key_type& __key)
        {
-       size_type __ret(0);
-       auto __pair = _Base::equal_range(__key);
-       for (auto __victim = __pair.first; __victim != __pair.second;)
+       size_type __count(0);
+       size_type __bucket_count = this->bucket_count();
+       auto __victims = _Base::equal_range(__key);
+       for (auto __victim = __victims.first; __victim != __victims.second;)
           {
             _M_invalidate(__victim);
             __victim = _Base::erase(__victim);
-           ++__ret;
+           ++__count;
           }
-
-       return __ret;
+       _M_check_rehashed(__bucket_count);

Is this a bug fix? It's not mentioned in the commit message.

    "Also, make existing unordered_set<>::erase perform the same
    bucket check as erase on unordered_multimap."

It seemed like an unintentional omission.
And I took the opportunity to regularize names.

+       return __count;
        }


Reply via email to