Skip to content

Commit 2df0254

Browse files
[ADT] Add SmallSet::insert_range (#131717)
This patch adds SmallSet::insert_range for consistency with DenseSet::insert_range and std::set::insert_range from C++23.
1 parent fc38982 commit 2df0254

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

llvm/include/llvm/ADT/SmallSet.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef LLVM_ADT_SMALLSET_H
1515
#define LLVM_ADT_SMALLSET_H
1616

17+
#include "llvm/ADT/ADL.h"
1718
#include "llvm/ADT/SmallPtrSet.h"
1819
#include "llvm/ADT/SmallVector.h"
1920
#include "llvm/ADT/iterator.h"
@@ -190,6 +191,10 @@ class SmallSet {
190191
insert(*I);
191192
}
192193

194+
template <typename Range> void insert_range(Range &&R) {
195+
insert(adl_begin(R), adl_end(R));
196+
}
197+
193198
bool erase(const T &V) {
194199
if (!isSmall())
195200
return Set.erase(V);

llvm/unittests/ADT/SmallSetTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ TEST(SmallSetTest, InsertPerfectFwd) {
127127
}
128128
}
129129

130+
TEST(SmallSetTest, InsertRange) {
131+
SmallSet<int, 4> s1;
132+
constexpr unsigned Args[] = {3, 1, 2};
133+
s1.insert_range(Args);
134+
EXPECT_THAT(s1, ::testing::UnorderedElementsAre(1, 2, 3));
135+
}
136+
130137
TEST(SmallSetTest, Grow) {
131138
SmallSet<int, 4> s1;
132139

0 commit comments

Comments
 (0)