[llvm] fc38982 - [ADT] Add SetVector::insert_range (#131715)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 18 00:19:52 PDT 2025
Author: Kazu Hirata
Date: 2025-03-18T00:19:48-07:00
New Revision: fc38982e93d12e0a77cdd8d9068bafdc79a75ce7
URL: https://github.com/llvm/llvm-project/commit/fc38982e93d12e0a77cdd8d9068bafdc79a75ce7
DIFF: https://github.com/llvm/llvm-project/commit/fc38982e93d12e0a77cdd8d9068bafdc79a75ce7.diff
LOG: [ADT] Add SetVector::insert_range (#131715)
This patch adds SetVector::insert_range for consistency with
DenseSet::insert_range and std::set::insert_range from C++23.
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 69931e02953d8..395b22685240f 100644
--- a/llvm/include/llvm/ADT/SetVector.h
+++ b/llvm/include/llvm/ADT/SetVector.h
@@ -20,6 +20,7 @@
#ifndef LLVM_ADT_SETVECTOR_H
#define LLVM_ADT_SETVECTOR_H
+#include "llvm/ADT/ADL.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/STLExtras.h"
@@ -184,6 +185,10 @@ class SetVector {
insert(*Start);
}
+ template <typename Range> void insert_range(Range &&R) {
+ insert(adl_begin(R), adl_end(R));
+ }
+
/// Remove an item from the set vector.
bool remove(const value_type& X) {
if constexpr (canBeSmall())
diff --git a/llvm/unittests/ADT/SetVectorTest.cpp b/llvm/unittests/ADT/SetVectorTest.cpp
index a0114c0e3509c..ee565a01fd922 100644
--- a/llvm/unittests/ADT/SetVectorTest.cpp
+++ b/llvm/unittests/ADT/SetVectorTest.cpp
@@ -12,6 +12,7 @@
#include "llvm/ADT/SetVector.h"
#include "llvm/ADT/SmallPtrSet.h"
+#include "gmock/gmock.h"
#include "gtest/gtest.h"
using namespace llvm;
@@ -86,3 +87,10 @@ TEST(SetVector, ConstPtrKeyTest) {
EXPECT_FALSE(S.contains(&j));
EXPECT_FALSE(S.contains((const int *)&j));
}
+
+TEST(SetVector, InsertRange) {
+ SetVector<unsigned> Set;
+ constexpr unsigned Args[] = {3, 1, 2};
+ Set.insert_range(Args);
+ EXPECT_THAT(Set, ::testing::ElementsAre(3, 1, 2));
+}
More information about the llvm-commits
mailing list