[llvm] [ADT] Add SmallSet::insert_range (PR #131717)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 17 20:51:08 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-adt
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
This patch adds SmallSet::insert_range for consistency with
DenseSet::insert_range and std::set::insert_range from C++23.
---
Full diff: https://github.com/llvm/llvm-project/pull/131717.diff
2 Files Affected:
- (modified) llvm/include/llvm/ADT/SmallSet.h (+5)
- (modified) llvm/unittests/ADT/SmallSetTest.cpp (+7)
``````````diff
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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/131717
More information about the llvm-commits
mailing list