[PATCH] D25629: [ADT] Add an initializer_list constructor to {Small, }DenseSet.
Justin Lebar via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 14 11:06:04 PDT 2016
jlebar created this revision.
jlebar added a reviewer: timshen.
jlebar added a subscriber: llvm-commits.
https://reviews.llvm.org/D25629
Files:
llvm/include/llvm/ADT/DenseSet.h
llvm/unittests/ADT/DenseSetTest.cpp
Index: llvm/unittests/ADT/DenseSetTest.cpp
===================================================================
--- llvm/unittests/ADT/DenseSetTest.cpp
+++ llvm/unittests/ADT/DenseSetTest.cpp
@@ -64,6 +64,21 @@
DenseSetTestTypes;
TYPED_TEST_CASE(DenseSetTest, DenseSetTestTypes);
+TYPED_TEST(DenseSetTest, InitializerList) {
+ TypeParam set({1, 2, 1, 4});
+ EXPECT_EQ(3u, set.size());
+ EXPECT_EQ(1u, set.count(1));
+ EXPECT_EQ(1u, set.count(2));
+ EXPECT_EQ(1u, set.count(4));
+ EXPECT_EQ(0u, set.count(3));
+}
+
+TYPED_TEST(DenseSetTest, EmptyInitializerList) {
+ TypeParam set({});
+ EXPECT_EQ(0u, set.size());
+ EXPECT_EQ(0u, set.count(0));
+}
+
TYPED_TEST(DenseSetTest, FindAsTest) {
auto &set = this->Set;
// Size tests
Index: llvm/include/llvm/ADT/DenseSet.h
===================================================================
--- llvm/include/llvm/ADT/DenseSet.h
+++ llvm/include/llvm/ADT/DenseSet.h
@@ -15,6 +15,7 @@
#define LLVM_ADT_DENSESET_H
#include "llvm/ADT/DenseMap.h"
+#include <initializer_list>
namespace llvm {
@@ -55,6 +56,11 @@
explicit DenseSetImpl(unsigned InitialReserve = 0) : TheMap(InitialReserve) {}
+ DenseSetImpl(std::initializer_list<ValueT> Elems)
+ : DenseSetImpl(Elems.size()) {
+ insert(Elems.begin(), Elems.end());
+ }
+
bool empty() const { return TheMap.empty(); }
size_type size() const { return TheMap.size(); }
size_t getMemorySize() const { return TheMap.getMemorySize(); }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25629.74716.patch
Type: text/x-patch
Size: 1475 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161014/426ea532/attachment.bin>
More information about the llvm-commits
mailing list