Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions llvm/include/llvm/ADT/STLExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions llvm/unittests/ADT/STLExtrasTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};

Expand Down