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

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 17 11:26:51 PDT 2020


Author: David Blaikie
Date: 2020-07-17T11:26:26-07:00
New Revision: d3ce3dc4867b80605a024d1f1b905a0d709992ca

URL: https://github.com/llvm/llvm-project/commit/d3ce3dc4867b80605a024d1f1b905a0d709992ca
DIFF: https://github.com/llvm/llvm-project/commit/d3ce3dc4867b80605a024d1f1b905a0d709992ca.diff

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

Matches C++20 API addition.

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

Added: 
    

Modified: 
    llvm/include/llvm/ADT/DenseSet.h
    llvm/unittests/ADT/DenseSetTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/DenseSet.h b/llvm/include/llvm/ADT/DenseSet.h
index 07edc3d8e4ec..dca217358ff8 100644
--- a/llvm/include/llvm/ADT/DenseSet.h
+++ b/llvm/include/llvm/ADT/DenseSet.h
@@ -173,6 +173,11 @@ class DenseSetImpl {
     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 
diff erent, 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
index 556bd46537db..ada53cac9b78 100644
--- a/llvm/unittests/ADT/DenseSetTest.cpp
+++ b/llvm/unittests/ADT/DenseSetTest.cpp
@@ -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));
 }
 }


        


More information about the llvm-commits mailing list