diff --git a/llvm/include/llvm/ADT/DenseSet.h b/llvm/include/llvm/ADT/DenseSet.h --- a/llvm/include/llvm/ADT/DenseSet.h +++ b/llvm/include/llvm/ADT/DenseSet.h @@ -173,6 +173,11 @@ return ConstIterator(TheMap.find(V)); } + /// Check if the set contains the given element. + bool contains(const_arg_type_t 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 diff --git a/llvm/unittests/ADT/DenseSetTest.cpp b/llvm/unittests/ADT/DenseSetTest.cpp --- a/llvm/unittests/ADT/DenseSetTest.cpp +++ b/llvm/unittests/ADT/DenseSetTest.cpp @@ -227,7 +227,7 @@ 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)); } }