Skip to content

Commit 6553753

Browse files
authored
[llvm][ADT] Add wrappers to std::fill (#146681)
This PR adds `llvm::fill` that accepts a range instead of begin/end iterator.
1 parent b59763a commit 6553753

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,17 @@ 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+
fill(V1, Val);
1599+
EXPECT_THAT(V1, ElementsAre(Val, Val, Val));
1600+
V2.resize(4);
1601+
fill(V2, Val);
1602+
EXPECT_THAT(V2, ElementsAre(Val, Val, Val, Val));
1603+
}
1604+
15941605
struct Foo;
15951606
struct Bar {};
15961607

0 commit comments

Comments
 (0)