[llvm] [ADT] Add a range constructor to SmallSetVector (PR #132645)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 23 16:01:12 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-adt
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
DenseSet recently gained a range constructor:
DenseSet<T> Dest(llvm::from_range, Src);
This patch adds the same signature to SmallSetVector for consistency.
---
Full diff: https://github.com/llvm/llvm-project/pull/132645.diff
2 Files Affected:
- (modified) llvm/include/llvm/ADT/SetVector.h (+4)
- (modified) llvm/unittests/ADT/SetVectorTest.cpp (+6)
``````````diff
diff --git a/llvm/include/llvm/ADT/SetVector.h b/llvm/include/llvm/ADT/SetVector.h
index 6ee9375b175b7..0692071adb391 100644
--- a/llvm/include/llvm/ADT/SetVector.h
+++ b/llvm/include/llvm/ADT/SetVector.h
@@ -386,6 +386,10 @@ class SmallSetVector : public SetVector<T, SmallVector<T, N>, DenseSet<T>, N> {
SmallSetVector(It Start, It End) {
this->insert(Start, End);
}
+
+ template <typename Range>
+ SmallSetVector(llvm::from_range_t, Range &&R)
+ : SmallSetVector(adl_begin(R), adl_end(R)) {}
};
} // end namespace llvm
diff --git a/llvm/unittests/ADT/SetVectorTest.cpp b/llvm/unittests/ADT/SetVectorTest.cpp
index 6ce4360cab90e..ff3c876deb458 100644
--- a/llvm/unittests/ADT/SetVectorTest.cpp
+++ b/llvm/unittests/ADT/SetVectorTest.cpp
@@ -100,3 +100,9 @@ TEST(SetVector, InsertRange) {
Set.insert_range(Args);
EXPECT_THAT(Set, ::testing::ElementsAre(3, 1, 2));
}
+
+TEST(SmallSetVector, CtorRange) {
+ constexpr unsigned Args[] = {3, 1, 2};
+ SmallSetVector<unsigned, 4> Set(llvm::from_range, Args);
+ EXPECT_THAT(Set, ::testing::ElementsAre(3, 1, 2));
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/132645
More information about the llvm-commits
mailing list