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 SetVector

Matches C++20 API addition.

Differential Revision: https://reviews.llvm.org/D83449
This commit is contained in:
David Blaikie 2020-07-17 10:41:03 -07:00
parent f4752de569
commit 3cfbc95ca8
2 changed files with 22 additions and 0 deletions

View File

@ -205,6 +205,11 @@ public:
return true;
}
/// Check if the SetVector contains the given key.
bool contains(const key_type &key) const {
return set_.find(key) != set_.end();
}
/// Count the number of elements of a given key in the SetVector.
/// \returns 0 if the element is not in the SetVector, 1 if it is.
size_type count(const key_type &key) const {

View File

@ -31,3 +31,20 @@ TEST(SetVector, EraseTest) {
EXPECT_EQ(2, *std::next(S.begin()));
}
TEST(SetVector, ContainsTest) {
SetVector<int> S;
S.insert(0);
S.insert(1);
S.insert(2);
EXPECT_TRUE(S.contains(0));
EXPECT_TRUE(S.contains(1));
EXPECT_TRUE(S.contains(2));
EXPECT_FALSE(S.contains(-1));
S.insert(2);
EXPECT_TRUE(S.contains(2));
S.remove(2);
EXPECT_FALSE(S.contains(2));
}