-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[llvm][ADT] Add wrappers to std::fill
#146681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@llvm/pr-subscribers-llvm-adt Author: Longsheng Mou (CoTinker) ChangesThis PR adds Full diff: https://github.com/llvm/llvm-project/pull/146681.diff 2 Files Affected:
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..14f5da1ff9549 100644
--- a/llvm/unittests/ADT/STLExtrasTest.cpp
+++ b/llvm/unittests/ADT/STLExtrasTest.cpp
@@ -1591,6 +1591,18 @@ TEST(STLExtrasTest, Includes) {
}
}
+TEST(STLExtrasTest, Fill) {
+ std::vector<int> V1 = {1, 2, 3};
+ std::vector<int> V2;
+ int Val = 4;
+ auto SameToVal = [&](int V) { return V == Val; };
+ fill(V1, Val);
+ EXPECT_TRUE(llvm::all_of(V1, SameToVal));
+ V2.resize(5);
+ fill(V2, Val);
+ EXPECT_TRUE(llvm::all_of(V2, SameToVal));
+}
+
struct Foo;
struct Bar {};
|
This PR adds `llvm::fill` that accepts a range instead of start/end iterator.
jurahul
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
kuhar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you also plan to add uninitialized_fill?
Sorry, currently, I have no plans to add |
This PR adds
llvm::fillthat accepts a range instead of begin/end iterator.