diff options
author | A. Jiang <de34@live.cn> | 2025-03-06 09:23:55 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-06 09:23:55 +0800 |
commit | c28c5089628a443e0f848c2860f5e59e68efe301 (patch) | |
tree | f96342e13bf7fb211ea34ed68db635087a499bcc /libcxx/test/std/algorithms | |
parent | 12c5a46c300eedb6cafc68b987abb9c1fa913e96 (diff) | |
download | llvm-c28c5089628a443e0f848c2860f5e59e68efe301.zip llvm-c28c5089628a443e0f848c2860f5e59e68efe301.tar.gz llvm-c28c5089628a443e0f848c2860f5e59e68efe301.tar.bz2 |
[libc++] Implement part of P2562R1: constexpr `ranges::stable_partition` (#129839)
Diffstat (limited to 'libcxx/test/std/algorithms')
4 files changed, 27 insertions, 8 deletions
diff --git a/libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/ranges_stable_partition.pass.cpp b/libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/ranges_stable_partition.pass.cpp index 5c72105..615cac8 100644 --- a/libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/ranges_stable_partition.pass.cpp +++ b/libcxx/test/std/algorithms/alg.modifying.operations/alg.partitions/ranges_stable_partition.pass.cpp @@ -13,12 +13,14 @@ // template<bidirectional_iterator I, sentinel_for<I> S, class Proj = identity, // indirect_unary_predicate<projected<I, Proj>> Pred> // requires permutable<I> -// subrange<I> stable_partition(I first, S last, Pred pred, Proj proj = {}); // Since C++20 +// constexpr subrange<I> // constexpr since C++26 +// stable_partition(I first, S last, Pred pred, Proj proj = {}); // Since C++20 // // template<bidirectional_range R, class Proj = identity, // indirect_unary_predicate<projected<iterator_t<R>, Proj>> Pred> // requires permutable<iterator_t<R>> -// borrowed_subrange_t<R> stable_partition(R&& r, Pred pred, Proj proj = {}); // Since C++20 +// constexpr borrowed_subrange_t<R> // constexpr since C++26 +// stable_partition(R&& r, Pred pred, Proj proj = {}); // Since C++20 #include <algorithm> #include <array> @@ -85,7 +87,8 @@ static_assert(!HasStablePartitionRange<R<PermutableNotForwardIterator>, UnaryPre static_assert(!HasStablePartitionRange<R<PermutableNotSwappable>, UnaryPred>); template <class Iter, class Sent, std::size_t N, class Pred> -void test_one(std::array<int, N> input, Pred pred, std::size_t partition_point, std::array<int, N> expected) { +TEST_CONSTEXPR_CXX26 void +test_one(std::array<int, N> input, Pred pred, std::size_t partition_point, std::array<int, N> expected) { auto neg_pred = [&](int x) { return !pred(x); }; { // (iterator, sentinel) overload. @@ -121,7 +124,7 @@ void test_one(std::array<int, N> input, Pred pred, std::size_t partition_point, } template <class Iter, class Sent> -void test_iterators_2() { +TEST_CONSTEXPR_CXX26 void test_iterators_2() { auto is_odd = [](int x) { return x % 2 != 0; }; // Empty sequence. @@ -157,19 +160,19 @@ void test_iterators_2() { } template <class Iter> -void test_iterators_1() { +TEST_CONSTEXPR_CXX26 void test_iterators_1() { test_iterators_2<Iter, Iter>(); test_iterators_2<Iter, sentinel_wrapper<Iter>>(); } -void test_iterators() { +TEST_CONSTEXPR_CXX26 void test_iterators() { test_iterators_1<bidirectional_iterator<int*>>(); test_iterators_1<random_access_iterator<int*>>(); test_iterators_1<contiguous_iterator<int*>>(); test_iterators_1<int*>(); } -void test() { +TEST_CONSTEXPR_CXX26 bool test() { test_iterators(); { // The algorithm is stable (equivalent elements remain in the same order). @@ -238,11 +241,15 @@ void test() { } } } + + return true; } int main(int, char**) { test(); - // Note: `stable_partition` is not `constexpr`. +#if TEST_STD_VER >= 26 + static_assert(test()); +#endif return 0; } diff --git a/libcxx/test/std/algorithms/ranges_robust_against_dangling.pass.cpp b/libcxx/test/std/algorithms/ranges_robust_against_dangling.pass.cpp index 0624a6c..e893030 100644 --- a/libcxx/test/std/algorithms/ranges_robust_against_dangling.pass.cpp +++ b/libcxx/test/std/algorithms/ranges_robust_against_dangling.pass.cpp @@ -197,8 +197,12 @@ constexpr bool test_all() { dangling_1st(std::ranges::shuffle, in, rand_gen()); dangling_1st(std::ranges::unique, in); dangling_1st(std::ranges::partition, in, unary_pred); +#if TEST_STD_VER < 26 if (!std::is_constant_evaluated()) +#endif + { dangling_1st(std::ranges::stable_partition, in, unary_pred); + } dangling_1st(std::ranges::sort, in); if (!std::is_constant_evaluated()) dangling_1st(std::ranges::stable_sort, in); diff --git a/libcxx/test/std/algorithms/ranges_robust_against_omitting_invoke.pass.cpp b/libcxx/test/std/algorithms/ranges_robust_against_omitting_invoke.pass.cpp index acd7640..3105a32 100644 --- a/libcxx/test/std/algorithms/ranges_robust_against_omitting_invoke.pass.cpp +++ b/libcxx/test/std/algorithms/ranges_robust_against_omitting_invoke.pass.cpp @@ -164,8 +164,12 @@ constexpr bool test_all() { // For `shuffle`, whether the given generator is invoked via `std::invoke` is not observable. test(std::ranges::unique, in, &Foo::binary_pred, &Bar::val); test(std::ranges::partition, in, &Foo::unary_pred, &Bar::val); +#if TEST_STD_VER < 26 if (!std::is_constant_evaluated()) +#endif + { test(std::ranges::stable_partition, in, &Foo::unary_pred, &Bar::val); + } test(std::ranges::sort, in, &Foo::binary_pred, &Bar::val); if (!std::is_constant_evaluated()) test(std::ranges::stable_sort, in, &Foo::binary_pred, &Bar::val); diff --git a/libcxx/test/std/algorithms/ranges_robust_against_proxy_iterators.pass.cpp b/libcxx/test/std/algorithms/ranges_robust_against_proxy_iterators.pass.cpp index ca1433b..578fecd 100644 --- a/libcxx/test/std/algorithms/ranges_robust_against_proxy_iterators.pass.cpp +++ b/libcxx/test/std/algorithms/ranges_robust_against_proxy_iterators.pass.cpp @@ -167,8 +167,12 @@ constexpr void run_tests() { } test(std::ranges::unique, in); test(std::ranges::partition, in, unary_pred); +#if TEST_STD_VER < 26 if (!std::is_constant_evaluated()) +#endif + { test(std::ranges::stable_partition, in, unary_pred); + } test(std::ranges::sort, in); if (!std::is_constant_evaluated()) test(std::ranges::stable_sort, in); |