diff --git a/llvm/include/llvm/ADT/DenseSet.h b/llvm/include/llvm/ADT/DenseSet.h index a307bd8c9198b..ac766e778df0d 100644 --- a/llvm/include/llvm/ADT/DenseSet.h +++ b/llvm/include/llvm/ADT/DenseSet.h @@ -14,6 +14,7 @@ #ifndef LLVM_ADT_DENSESET_H #define LLVM_ADT_DENSESET_H +#include "llvm/ADT/ADL.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMapInfo.h" #include "llvm/Support/MathExtras.h" @@ -237,6 +238,10 @@ class DenseSetImpl { for (; I != E; ++I) insert(*I); } + + template void insert_range(Range &&R) { + insert(adl_begin(R), adl_end(R)); + } }; /// Equality comparison for DenseSet. diff --git a/llvm/unittests/ADT/DenseSetTest.cpp b/llvm/unittests/ADT/DenseSetTest.cpp index f14542eafc251..8fc2bab44b124 100644 --- a/llvm/unittests/ADT/DenseSetTest.cpp +++ b/llvm/unittests/ADT/DenseSetTest.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "llvm/ADT/DenseSet.h" +#include "gmock/gmock.h" #include "gtest/gtest.h" #include @@ -32,6 +33,13 @@ TEST(DenseSetTest, DoubleEntrySetTest) { EXPECT_EQ(0u, set.count(2)); } +TEST(DenseSetTest, InsertRange) { + llvm::DenseSet set; + constexpr unsigned Args[] = {3, 1, 2}; + set.insert_range(Args); + EXPECT_THAT(set, ::testing::UnorderedElementsAre(1, 2, 3)); +} + struct TestDenseSetInfo { static inline unsigned getEmptyKey() { return ~0; } static inline unsigned getTombstoneKey() { return ~0U - 1; }