1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

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

Matches C++20 API addition.

Differential Revision: https://reviews.llvm.org/D83449
This commit is contained in:
David Blaikie 2020-07-17 10:43:12 -07:00
parent 479337797c
commit 8ab112dbf4
2 changed files with 22 additions and 0 deletions

View File

@ -45,6 +45,9 @@ public:
insert(const StringMapEntry<ValueTy> &mapEntry) {
return insert(mapEntry.getKey());
}
/// Check if the set contains the given \c key.
bool contains(StringRef key) const { return Base::FindKey(key) != -1; }
};
} // end namespace llvm

View File

@ -53,4 +53,23 @@ TEST_F(StringSetTest, EmptyString) {
EXPECT_EQ(Count, 1UL);
}
TEST_F(StringSetTest, Contains) {
StringSet<> Set;
EXPECT_FALSE(Set.contains(""));
EXPECT_FALSE(Set.contains("test"));
Set.insert("");
Set.insert("test");
EXPECT_TRUE(Set.contains(""));
EXPECT_TRUE(Set.contains("test"));
Set.insert("test");
EXPECT_TRUE(Set.contains(""));
EXPECT_TRUE(Set.contains("test"));
Set.erase("test");
EXPECT_TRUE(Set.contains(""));
EXPECT_FALSE(Set.contains("test"));
}
} // end anonymous namespace