OSDN Git Service

[ADT] Add missing const_iterator DenseSet::find() const
authorVitaly Buka <vitalybuka@google.com>
Wed, 5 Oct 2016 20:36:39 +0000 (20:36 +0000)
committerVitaly Buka <vitalybuka@google.com>
Wed, 5 Oct 2016 20:36:39 +0000 (20:36 +0000)
Summary: Probably overlooked.

Reviewers: eugenis, dblaikie

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283377 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 8280f6f..fe44b43 100644 (file)
@@ -135,6 +135,9 @@ public:
   const_iterator end() const { return ConstIterator(TheMap.end()); }
 
   iterator find(const ValueT &V) { return Iterator(TheMap.find(V)); }
+  const_iterator find(const ValueT &V) const {
+    return ConstIterator(TheMap.find(V));
+  }
 
   /// Alternative version of find() which allows a different, and possibly less
   /// expensive, key type.
index 72af21e..1e1978e 100644 (file)
@@ -7,19 +7,16 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "gtest/gtest.h"
 #include "llvm/ADT/DenseSet.h"
+#include "gtest/gtest.h"
+#include <type_traits>
 
 using namespace llvm;
 
 namespace {
 
-// Test fixture
-class DenseSetTest : public testing::Test {
-};
-
 // Test hashing with a set of only two entries.
-TEST_F(DenseSetTest, DoubleEntrySetTest) {
+TEST(DenseSetTest, DoubleEntrySetTest) {
   llvm::DenseSet<unsigned> set(2);
   set.insert(0);
   set.insert(1);
@@ -42,12 +39,29 @@ struct TestDenseSetInfo {
   }
 };
 
-TEST(DenseSetCustomTest, FindAsTest) {
-  DenseSet<unsigned, TestDenseSetInfo> set;
-  set.insert(0);
-  set.insert(1);
-  set.insert(2);
+// Test fixture
+template <typename T> class DenseSetTest : public testing::Test {
+protected:
+  T Set = GetTestSet();
+
+private:
+  static T GetTestSet() {
+    typename std::remove_const<T>::type Set;
+    Set.insert(0);
+    Set.insert(1);
+    Set.insert(2);
+    return Set;
+  }
+};
+
+// Register these types for testing.
+typedef ::testing::Types<DenseSet<unsigned, TestDenseSetInfo>,
+                         const DenseSet<unsigned, TestDenseSetInfo>>
+    DenseSetTestTypes;
+TYPED_TEST_CASE(DenseSetTest, DenseSetTestTypes);
 
+TYPED_TEST(DenseSetTest, FindAsTest) {
+  auto &set = this->Set;
   // Size tests
   EXPECT_EQ(3u, set.size());