[libcxx-commits] [libcxx] [libc++] Improve the performance of std::make_heap a bit (PR #154092)

Prabhu Rajasekaran via libcxx-commits libcxx-commits at lists.llvm.org
Mon Sep 22 10:47:49 PDT 2025


================
@@ -31,13 +33,23 @@ inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
 __make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare&& __comp) {
   __comp_ref_type<_Compare> __comp_ref = __comp;
 
-  using difference_type = typename iterator_traits<_RandomAccessIterator>::difference_type;
-  difference_type __n   = __last - __first;
+  using __diff_t     = __iter_diff_t<_RandomAccessIterator>;
+  const __diff_t __n = __last - __first;
+
+  static const bool __assume_both_children = is_arithmetic<__iter_value_type<_RandomAccessIterator> >::value;
----------------
Prabhuk wrote:

Use of static within constexpr seems to be failing with gcc for C++ versions before 23. Does not seem to fail with clang. I am working on getting a simple reproducer but wanted to leave a message for the code owners to be aware of. 

```
error: '__assume_both_children' defined 'static' in 'constexpr' function only available with '-std=c++23' or '-std=gnu++23' [-Wtemplate-body]
   39 |   static const bool __assume_both_children = is_arithmetic<__iter_value_type<_RandomAccessIterator> >::value;
      |                     ^~~~~~~~~~~~~~~~~~~~~~
```

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


More information about the libcxx-commits mailing list