[llvm-branch-commits] [llvm] a22e8d3 - Revert "Make STLExtras's (all|any|none)_of() Utility Functions Constexpr-Frie…"
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sat Dec 20 11:29:52 PST 2025
Author: Michał Górny
Date: 2025-12-20T20:29:48+01:00
New Revision: a22e8d3ed9000e24fec80c6bd4b3ad7261cf5ccd
URL: https://github.com/llvm/llvm-project/commit/a22e8d3ed9000e24fec80c6bd4b3ad7261cf5ccd
DIFF: https://github.com/llvm/llvm-project/commit/a22e8d3ed9000e24fec80c6bd4b3ad7261cf5ccd.diff
LOG: Revert "Make STLExtras's (all|any|none)_of() Utility Functions Constexpr-Frie…"
This reverts commit 21fd8cc2a5584795107f384c5bf8d36c141188fc.
Added:
Modified:
llvm/include/llvm/ADT/STLExtras.h
llvm/unittests/ADT/STLExtrasTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index d4632ab72e563..409cd7b60fa00 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -638,10 +638,10 @@ make_early_inc_range(RangeT &&Range) {
// Forward declarations required by zip_shortest/zip_equal/zip_first/zip_longest
template <typename R, typename UnaryPredicate>
-constexpr bool all_of(R &&range, UnaryPredicate P);
+bool all_of(R &&range, UnaryPredicate P);
template <typename R, typename UnaryPredicate>
-constexpr bool any_of(R &&range, UnaryPredicate P);
+bool any_of(R &&range, UnaryPredicate P);
template <typename T> bool all_equal(std::initializer_list<T> Values);
@@ -1734,31 +1734,22 @@ UnaryFunction for_each(R &&Range, UnaryFunction F) {
/// Provide wrappers to std::all_of which take ranges instead of having to pass
/// begin/end explicitly.
template <typename R, typename UnaryPredicate>
-constexpr bool all_of(R &&Range, UnaryPredicate P) {
- // TODO: switch back to std::all_of() after it becomes constexpr in c++20.
- for (auto I = adl_begin(Range), E = adl_end(Range); I != E; ++I)
- if (!P(*I))
- return false;
- return true;
+bool all_of(R &&Range, UnaryPredicate P) {
+ return std::all_of(adl_begin(Range), adl_end(Range), P);
}
/// Provide wrappers to std::any_of which take ranges instead of having to pass
/// begin/end explicitly.
template <typename R, typename UnaryPredicate>
-constexpr bool any_of(R &&Range, UnaryPredicate P) {
- // TODO: switch back to std::any_of() after it becomes constexpr in c++20.
- for (auto I = adl_begin(Range), E = adl_end(Range); I != E; ++I)
- if (P(*I))
- return true;
- return false;
+bool any_of(R &&Range, UnaryPredicate P) {
+ return std::any_of(adl_begin(Range), adl_end(Range), P);
}
/// Provide wrappers to std::none_of which take ranges instead of having to pass
/// begin/end explicitly.
template <typename R, typename UnaryPredicate>
-constexpr bool none_of(R &&Range, UnaryPredicate P) {
- // TODO: switch back to std::none_of() after it becomes constexpr in c++20.
- return !any_of(Range, P);
+bool none_of(R &&Range, UnaryPredicate P) {
+ return std::none_of(adl_begin(Range), adl_end(Range), P);
}
/// Provide wrappers to std::fill which take ranges instead of having to pass
diff --git a/llvm/unittests/ADT/STLExtrasTest.cpp b/llvm/unittests/ADT/STLExtrasTest.cpp
index da84345eecda8..dbf439b8d63a0 100644
--- a/llvm/unittests/ADT/STLExtrasTest.cpp
+++ b/llvm/unittests/ADT/STLExtrasTest.cpp
@@ -1260,25 +1260,6 @@ TEST(STLExtras, MoveRange) {
EXPECT_TRUE(llvm::all_of(V4, HasVal));
}
-TEST(STLExtrasTest, AllOfAnyOfNoneOfConstexpr) {
- // Verify constexpr evaluation works. Functional correctness is tested in
- // runtime tests (e.g., MoveRange).
- constexpr std::array<int, 3> Arr = {1, 2, 3};
- static_assert(all_of(Arr, [](int X) { return X > 0; }));
- static_assert(any_of(Arr, [](int X) { return X == 2; }));
- static_assert(none_of(Arr, [](int X) { return X < 0; }));
-
- // Verify constexpr works with C-style arrays.
- constexpr int CArr[] = {1, 2};
- static_assert(all_of(CArr, [](int X) { return X > 0; }));
-
- // Verify empty range edge case.
- constexpr std::array<int, 0> Empty = {};
- static_assert(all_of(Empty, [](int) { return false; }));
- static_assert(!any_of(Empty, [](int) { return true; }));
- static_assert(none_of(Empty, [](int) { return true; }));
-}
-
TEST(STLExtras, Unique) {
std::vector<int> V = {1, 5, 5, 4, 3, 3, 3};
More information about the llvm-branch-commits
mailing list