mirror of
https://github.com/RPCS3/llvm.git
synced 2025-01-27 05:32:22 +00:00
[ADT] Add an initializer_list constructor to {Small,}DenseSet.
Reviewers: timshen Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D25629 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284433 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6461aabcfc
commit
afb36183fc
@ -15,6 +15,7 @@
|
|||||||
#define LLVM_ADT_DENSESET_H
|
#define LLVM_ADT_DENSESET_H
|
||||||
|
|
||||||
#include "llvm/ADT/DenseMap.h"
|
#include "llvm/ADT/DenseMap.h"
|
||||||
|
#include <initializer_list>
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
@ -55,6 +56,11 @@ public:
|
|||||||
|
|
||||||
explicit DenseSetImpl(unsigned InitialReserve = 0) : TheMap(InitialReserve) {}
|
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(); }
|
bool empty() const { return TheMap.empty(); }
|
||||||
size_type size() const { return TheMap.size(); }
|
size_type size() const { return TheMap.size(); }
|
||||||
size_t getMemorySize() const { return TheMap.getMemorySize(); }
|
size_t getMemorySize() const { return TheMap.getMemorySize(); }
|
||||||
|
@ -64,6 +64,21 @@ typedef ::testing::Types<DenseSet<unsigned, TestDenseSetInfo>,
|
|||||||
DenseSetTestTypes;
|
DenseSetTestTypes;
|
||||||
TYPED_TEST_CASE(DenseSetTest, 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) {
|
TYPED_TEST(DenseSetTest, FindAsTest) {
|
||||||
auto &set = this->Set;
|
auto &set = this->Set;
|
||||||
// Size tests
|
// Size tests
|
||||||
|
Loading…
x
Reference in New Issue
Block a user