[libcxx-commits] [libcxx] [libc++][C++26] P2562R1: `constexpr` Stable Sorting (PR #110320)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Dec 10 07:53:22 PST 2024


================
@@ -148,22 +154,37 @@ int main(int, char**)
     test_sort_<6>();
     test_sort_<7>();
     test_sort_<8>();
-
-    test_larger_sorts(256);
-    test_larger_sorts(257);
-    test_larger_sorts(499);
-    test_larger_sorts(500);
-    test_larger_sorts(997);
-    test_larger_sorts(1000);
-    test_larger_sorts(1009);
+  }
+
+  test_larger_sorts<256>();
+  test_larger_sorts<257>();
+#if TEST_STD_VER >= 26
+  if !consteval // only runtime tests bc. error: "constexpr evaluation hit maximum step limit"
+#endif
+  {
+    test_larger_sorts<499>();
+    test_larger_sorts<500>();
+    test_larger_sorts<997>();
+    test_larger_sorts<1000>();
+    test_larger_sorts<1009>();
+  }
 
 #if !defined(TEST_HAS_NO_EXCEPTIONS)
-    { // check that the algorithm works without memory
-        std::vector<int> vec(150, 3);
-        getGlobalMemCounter()->throw_after = 0;
-        std::stable_sort(vec.begin(), vec.end());
-    }
+#  if TEST_STD_VER >= 26
+  if !consteval
+#  endif
+  { // check that the algorithm works without memory
+    std::vector<int> vec(150, 3);
+    getGlobalMemCounter()->throw_after = 0;
+    std::stable_sort(vec.begin(), vec.end());
+  }
 #endif // !defined(TEST_HAS_NO_EXCEPTIONS)
+}
 
+int main(int, char**) {
+  test();
+#if TEST_STD_VER >= 26
+  static_assert((test(), true));
----------------
ldionne wrote:

```suggestion
  static_assert(test());
```

While what you wrote is entirely valid (and in fact probably better!), we have consistent precedent for making `test` a `bool`-returning function that always returns `true`. It's a nitpick, but let's be consistent.

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


More information about the libcxx-commits mailing list