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

Matches C++20 API addition.

Differential Revision: https://reviews.llvm.org/D83449
This commit is contained in:
David Blaikie 2020-07-17 10:40:42 -07:00
parent 62d88a1c79
commit d3ce3dc486
2 changed files with 7 additions and 2 deletions

View File

@ -173,6 +173,11 @@ public:
return ConstIterator(TheMap.find(V));
}
/// Check if the set contains the given element.
bool contains(const_arg_type_t<ValueT> V) const {
return TheMap.find(V) != TheMap.end();
}
/// Alternative version of find() which allows a different, and possibly less
/// expensive, key type.
/// The DenseMapInfo is responsible for supplying methods

View File

@ -227,7 +227,7 @@ TEST(DenseSetCustomTest, ConstTest) {
Map.insert(B);
EXPECT_EQ(Map.count(B), 1u);
EXPECT_EQ(Map.count(C), 1u);
EXPECT_NE(Map.find(B), Map.end());
EXPECT_NE(Map.find(C), Map.end());
EXPECT_TRUE(Map.contains(B));
EXPECT_TRUE(Map.contains(C));
}
}