1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 10:42:39 +01:00

[llvm] Add contains(KeyType) -> bool methods to SmallPtrSet

Matches C++20 API addition.

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

(cherry picked from commit a0385bd7acd6e1d16224b4257f4cb50e59f1d75e)
This commit is contained in:
David Blaikie 2020-07-17 10:41:35 -07:00 committed by Hans Wennborg
parent b157b648ba
commit a654ae5458
2 changed files with 34 additions and 3 deletions

View File

@ -378,6 +378,9 @@ public:
iterator find(ConstPtrType Ptr) const { iterator find(ConstPtrType Ptr) const {
return makeIterator(find_imp(ConstPtrTraits::getAsVoidPointer(Ptr))); return makeIterator(find_imp(ConstPtrTraits::getAsVoidPointer(Ptr)));
} }
bool contains(ConstPtrType Ptr) const {
return find_imp(ConstPtrTraits::getAsVoidPointer(Ptr)) != EndPointer();
}
template <typename IterT> template <typename IterT>
void insert(IterT I, IterT E) { void insert(IterT I, IterT E) {

View File

@ -313,8 +313,8 @@ TEST(SmallPtrSetTest, ConstTest) {
IntSet.insert(B); IntSet.insert(B);
EXPECT_EQ(IntSet.count(B), 1u); EXPECT_EQ(IntSet.count(B), 1u);
EXPECT_EQ(IntSet.count(C), 1u); EXPECT_EQ(IntSet.count(C), 1u);
EXPECT_NE(IntSet.find(B), IntSet.end()); EXPECT_TRUE(IntSet.contains(B));
EXPECT_NE(IntSet.find(C), IntSet.end()); EXPECT_TRUE(IntSet.contains(C));
} }
// Verify that we automatically get the const version of PointerLikeTypeTraits // Verify that we automatically get the const version of PointerLikeTypeTraits
@ -327,7 +327,7 @@ TEST(SmallPtrSetTest, ConstNonPtrTest) {
TestPair Pair(&A[0], 1); TestPair Pair(&A[0], 1);
IntSet.insert(Pair); IntSet.insert(Pair);
EXPECT_EQ(IntSet.count(Pair), 1u); EXPECT_EQ(IntSet.count(Pair), 1u);
EXPECT_NE(IntSet.find(Pair), IntSet.end()); EXPECT_TRUE(IntSet.contains(Pair));
} }
// Test equality comparison. // Test equality comparison.
@ -367,3 +367,31 @@ TEST(SmallPtrSetTest, EqualityComparison) {
EXPECT_NE(c, e); EXPECT_NE(c, e);
EXPECT_NE(e, d); EXPECT_NE(e, d);
} }
TEST(SmallPtrSetTest, Contains) {
SmallPtrSet<int *, 2> Set;
int buf[4] = {0, 11, 22, 11};
EXPECT_FALSE(Set.contains(&buf[0]));
EXPECT_FALSE(Set.contains(&buf[1]));
Set.insert(&buf[0]);
Set.insert(&buf[1]);
EXPECT_TRUE(Set.contains(&buf[0]));
EXPECT_TRUE(Set.contains(&buf[1]));
EXPECT_FALSE(Set.contains(&buf[3]));
Set.insert(&buf[1]);
EXPECT_TRUE(Set.contains(&buf[0]));
EXPECT_TRUE(Set.contains(&buf[1]));
EXPECT_FALSE(Set.contains(&buf[3]));
Set.erase(&buf[1]);
EXPECT_TRUE(Set.contains(&buf[0]));
EXPECT_FALSE(Set.contains(&buf[1]));
Set.insert(&buf[1]);
Set.insert(&buf[2]);
EXPECT_TRUE(Set.contains(&buf[0]));
EXPECT_TRUE(Set.contains(&buf[1]));
EXPECT_TRUE(Set.contains(&buf[2]));
}