[llvm] 0175dce - [ADT] Add a range constructor to SmallSetVector (#132645)

via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 23 19:12:56 PDT 2025


Author: Kazu Hirata
Date: 2025-03-23T19:12:53-07:00
New Revision: 0175dce1380de64f4e0f627093b8f4858e354431

URL: https://github.com/llvm/llvm-project/commit/0175dce1380de64f4e0f627093b8f4858e354431
DIFF: https://github.com/llvm/llvm-project/commit/0175dce1380de64f4e0f627093b8f4858e354431.diff

LOG: [ADT] Add a range constructor to SmallSetVector (#132645)

DenseSet recently gained a range constructor:

  DenseSet<T> Dest(llvm::from_range, Src);

This patch adds the same signature to SmallSetVector for consistency.

Added: 
    

Modified: 
    llvm/include/llvm/ADT/SetVector.h
    llvm/unittests/ADT/SetVectorTest.cpp

Removed: 
    


################################################################################
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