Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions llvm/unittests/ADT/STLExtrasTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 IsSameAsVal = [&](int V) { return V == Val; };
fill(V1, Val);
EXPECT_TRUE(llvm::all_of(V1, IsSameAsVal));
V2.resize(5);
fill(V2, Val);
EXPECT_TRUE(llvm::all_of(V2, IsSameAsVal));
}

struct Foo;
struct Bar {};

Expand Down
Loading