[llvm] 2df0254 - [ADT] Add SmallSet::insert_range (#131717)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 18 00:20:18 PDT 2025
Author: Kazu Hirata
Date: 2025-03-18T00:20:15-07:00
New Revision: 2df02548289faa34629814fd851667d45db0bb1b
URL: https://github.com/llvm/llvm-project/commit/2df02548289faa34629814fd851667d45db0bb1b
DIFF: https://github.com/llvm/llvm-project/commit/2df02548289faa34629814fd851667d45db0bb1b.diff
LOG: [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.
Added:
Modified:
llvm/include/llvm/ADT/SmallSet.h
llvm/unittests/ADT/SmallSetTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/SmallSet.h b/llvm/include/llvm/ADT/SmallSet.h
index ed3c6bfd3418d..163690edda1bf 100644
--- a/llvm/include/llvm/ADT/SmallSet.h
+++ b/llvm/include/llvm/ADT/SmallSet.h
@@ -14,6 +14,7 @@
#ifndef LLVM_ADT_SMALLSET_H
#define LLVM_ADT_SMALLSET_H
+#include "llvm/ADT/ADL.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/iterator.h"
@@ -190,6 +191,10 @@ class SmallSet {
insert(*I);
}
+ template <typename Range> void insert_range(Range &&R) {
+ insert(adl_begin(R), adl_end(R));
+ }
+
bool erase(const T &V) {
if (!isSmall())
return Set.erase(V);
diff --git a/llvm/unittests/ADT/SmallSetTest.cpp b/llvm/unittests/ADT/SmallSetTest.cpp
index 2feb0b1feb421..7d2431d4832a9 100644
--- a/llvm/unittests/ADT/SmallSetTest.cpp
+++ b/llvm/unittests/ADT/SmallSetTest.cpp
@@ -127,6 +127,13 @@ TEST(SmallSetTest, InsertPerfectFwd) {
}
}
+TEST(SmallSetTest, InsertRange) {
+ SmallSet<int, 4> s1;
+ constexpr unsigned Args[] = {3, 1, 2};
+ s1.insert_range(Args);
+ EXPECT_THAT(s1, ::testing::UnorderedElementsAre(1, 2, 3));
+}
+
TEST(SmallSetTest, Grow) {
SmallSet<int, 4> s1;
More information about the llvm-commits
mailing list