Skip to content

Commit df0e75f

Browse files
committed
[llvm][ADT] Add wrappers to std::fill
This PR adds `llvm::fill` that accepts a range instead of start/end iterator.
1 parent 9eac5f7 commit df0e75f

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

llvm/include/llvm/ADT/STLExtras.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,6 +1759,12 @@ bool none_of(R &&Range, UnaryPredicate P) {
17591759
return std::none_of(adl_begin(Range), adl_end(Range), P);
17601760
}
17611761

1762+
/// Provide wrappers to std::fill which take ranges instead of having to pass
1763+
/// begin/end explicitly.
1764+
template <typename R, typename T> void fill(R &&Range, T &&Value) {
1765+
std::fill(adl_begin(Range), adl_end(Range), std::forward<T>(Value));
1766+
}
1767+
17621768
/// Provide wrappers to std::find which take ranges instead of having to pass
17631769
/// begin/end explicitly.
17641770
template <typename R, typename T> auto find(R &&Range, const T &Val) {

llvm/unittests/ADT/STLExtrasTest.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,18 @@ TEST(STLExtrasTest, Includes) {
15911591
}
15921592
}
15931593

1594+
TEST(STLExtrasTest, Fill) {
1595+
std::vector<int> V1 = {1, 2, 3};
1596+
std::vector<int> V2;
1597+
int Val = 4;
1598+
auto IsSameAsVal = [&](int V) { return V == Val; };
1599+
fill(V1, Val);
1600+
EXPECT_TRUE(llvm::all_of(V1, IsSameAsVal));
1601+
V2.resize(5);
1602+
fill(V2, Val);
1603+
EXPECT_TRUE(llvm::all_of(V2, IsSameAsVal));
1604+
}
1605+
15941606
struct Foo;
15951607
struct Bar {};
15961608

0 commit comments

Comments
 (0)