[libcxx-commits] [libcxx] [libc++] Support `constexpr` for `std::stable_sort` in radix sort branch (PR #125284)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Mon Feb 3 06:33:36 PST 2025


=?utf-8?b?0JTQvNC40YLRgNC40Lkg0JjQtw=?=,
=?utf-8?b?0JTQvNC40YLRgNC40Lkg0JjQtw=?Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/125284 at github.com>


================
@@ -253,6 +253,12 @@ _LIBCPP_CONSTEXPR_SINCE_CXX26 void __stable_sort(
   if constexpr (__allowed_radix_sort) {
     if (__len <= __buff_size && __len >= static_cast<difference_type>(__radix_sort_min_bound<value_type>()) &&
         __len <= static_cast<difference_type>(__radix_sort_max_bound<value_type>())) {
+      for (auto* __p = __buff; __p < __buff + __buff_size; ++__p) {
+        std::__construct_at(__p, 0);
+      }
+      __destruct_n __d(__buff_size);
+      unique_ptr<value_type, __destruct_n&> __h2(__buff, __d);
----------------
philnik777 wrote:

This is all only required for `constexpr` support, right? I'm pretty sure you can drop the destruction, since the elements should always be trivial. For the construction, I think we don't need the zero and we should probably only do it during constant evaluation.

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


More information about the libcxx-commits mailing list