[llvm] [ADT] Add a range constructor to SmallSetVector (PR #132645)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 23 16:00:38 PDT 2025
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/132645
DenseSet recently gained a range constructor:
DenseSet<T> Dest(llvm::from_range, Src);
This patch adds the same signature to SmallSetVector for consistency.
>From c417e26b0c1af9988645168a1934819d5f8b3fee Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sun, 23 Mar 2025 15:31:19 -0700
Subject: [PATCH] [ADT] Add a range constructor to SmallSetVector
DenseSet recently gained a range constructor:
DenseSet<T> Dest(llvm::from_range, Src);
This patch adds the same signature to SmallSetVector for consistency.
---
llvm/include/llvm/ADT/SetVector.h | 4 ++++
llvm/unittests/ADT/SetVectorTest.cpp | 6 ++++++
2 files changed, 10 insertions(+)
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));
+}
More information about the llvm-commits
mailing list