[PATCH] D24689: [ADT] Add missing const_iterator DenseSet::find() const

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 28 14:57:20 PDT 2016


vitalybuka updated this revision to Diff 72905.
vitalybuka added a comment.

rebase


https://reviews.llvm.org/D24689

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

Index: unittests/ADT/DenseSetTest.cpp
===================================================================
--- unittests/ADT/DenseSetTest.cpp
+++ unittests/ADT/DenseSetTest.cpp
@@ -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 @@
   }
 };
 
-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());
 
Index: include/llvm/ADT/DenseSet.h
===================================================================
--- include/llvm/ADT/DenseSet.h
+++ include/llvm/ADT/DenseSet.h
@@ -135,6 +135,9 @@
   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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24689.72905.patch
Type: text/x-patch
Size: 2072 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160928/e0370c38/attachment.bin>


More information about the llvm-commits mailing list