[ADT] Add an initializer_list constructor to {Small,}DenseSet.

Reviewers: timshen

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D25629

llvm-svn: 284433
This commit is contained in:
Justin Lebar 2016-10-17 22:24:32 +00:00
parent 4bccb581bf
commit 61b9b6a9d5
2 changed files with 21 additions and 0 deletions

View File

@ -15,6 +15,7 @@
#define LLVM_ADT_DENSESET_H
#include "llvm/ADT/DenseMap.h"
#include <initializer_list>
namespace llvm {
@ -55,6 +56,11 @@ public:
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(); }

View File

@ -64,6 +64,21 @@ typedef ::testing::Types<DenseSet<unsigned, TestDenseSetInfo>,
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