[llvm] 6553753 - [llvm][ADT] Add wrappers to `std::fill` (#146681)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 2 23:32:51 PDT 2025
Author: Longsheng Mou
Date: 2025-07-03T14:32:47+08:00
New Revision: 65537539e12912cfb614948c8cd4acbedd777284
URL: https://github.com/llvm/llvm-project/commit/65537539e12912cfb614948c8cd4acbedd777284
DIFF: https://github.com/llvm/llvm-project/commit/65537539e12912cfb614948c8cd4acbedd777284.diff
LOG: [llvm][ADT] Add wrappers to `std::fill` (#146681)
This PR adds `llvm::fill` that accepts a range instead of begin/end
iterator.
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 eea06cfb99ba2..b23188cbdadeb 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -1759,6 +1759,12 @@ 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
+/// begin/end explicitly.
+template <typename R, typename T> void fill(R &&Range, T &&Value) {
+ std::fill(adl_begin(Range), adl_end(Range), std::forward<T>(Value));
+}
+
/// Provide wrappers to std::find which take ranges instead of having to pass
/// begin/end explicitly.
template <typename R, typename T> auto find(R &&Range, const T &Val) {
diff --git a/llvm/unittests/ADT/STLExtrasTest.cpp b/llvm/unittests/ADT/STLExtrasTest.cpp
index 286cfa745fd14..9fda0d912a2f5 100644
--- a/llvm/unittests/ADT/STLExtrasTest.cpp
+++ b/llvm/unittests/ADT/STLExtrasTest.cpp
@@ -1591,6 +1591,17 @@ TEST(STLExtrasTest, Includes) {
}
}
+TEST(STLExtrasTest, Fill) {
+ std::vector<int> V1 = {1, 2, 3};
+ std::vector<int> V2;
+ int Val = 4;
+ fill(V1, Val);
+ EXPECT_THAT(V1, ElementsAre(Val, Val, Val));
+ V2.resize(4);
+ fill(V2, Val);
+ EXPECT_THAT(V2, ElementsAre(Val, Val, Val, Val));
+}
+
struct Foo;
struct Bar {};
More information about the llvm-commits
mailing list