Skip to content

Commit f6ad65a

Browse files
[ADT] Add SmallPtrSet::insert_range (#131716)
This pach adds SmallPtrSet::insert_range for consistency with DenseSet::insert_range and std::set::insert_range from C++23.
1 parent 2df0254 commit f6ad65a

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

llvm/include/llvm/ADT/SmallPtrSet.h

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

18+
#include "llvm/ADT/ADL.h"
1819
#include "llvm/ADT/EpochTracker.h"
1920
#include "llvm/Support/MathExtras.h"
2021
#include "llvm/Support/ReverseIteration.h"
@@ -469,6 +470,10 @@ class SmallPtrSetImpl : public SmallPtrSetImplBase {
469470
insert(IL.begin(), IL.end());
470471
}
471472

473+
template <typename Range> void insert_range(Range &&R) {
474+
insert(adl_begin(R), adl_end(R));
475+
}
476+
472477
iterator begin() const {
473478
if (shouldReverseIterate())
474479
return makeIterator(EndPointer() - 1);

llvm/unittests/ADT/SmallPtrSetTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,14 @@ TEST(SmallPtrSetTest, RemoveIf) {
411411
EXPECT_FALSE(Removed);
412412
}
413413

414+
TEST(SmallPtrSetTest, InsertRange) {
415+
int Vals[3] = {0, 1, 2};
416+
SmallPtrSet<int *, 4> Set;
417+
int *Args[] = {&Vals[2], &Vals[0], &Vals[1]};
418+
Set.insert_range(Args);
419+
EXPECT_THAT(Set, UnorderedElementsAre(&Vals[0], &Vals[1], &Vals[2]));
420+
}
421+
414422
TEST(SmallPtrSetTest, Reserve) {
415423
// Check that we don't do anything silly when using reserve().
416424
SmallPtrSet<int *, 4> Set;

0 commit comments

Comments
 (0)