[libcxx-commits] [libcxx] [libc++] __key_equiv is sometimes 2x expensive (PR #175087)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jan 20 01:44:54 PST 2026


================
@@ -50,7 +51,7 @@ __unique(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) {
 template <class _ForwardIterator, class _BinaryPredicate>
 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
 unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) {
-  return std::__unique<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __pred).first;
+  return std::__unique_sorted_range<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __pred).first;
----------------
philnik777 wrote:

Duplicating the code is one option. Another option would be a somewhat different name. Maybe something like `__deduplicate_if`? IDK. I'm kinda tempted to say we should just introduce a flat_{set,map}-specific algorithm that takes the underlying container and destroys the non-unique elements. That would give us an API to improve this more (e.g. by making use of trivially relocatable concepts).

https://github.com/llvm/llvm-project/pull/175087


More information about the libcxx-commits mailing list