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

Vitaly Buka via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 5 13:45:50 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL283377: [ADT] Add missing const_iterator DenseSet::find() const (authored by vitalybuka).

Changed prior to commit:
  https://reviews.llvm.org/D24689?vs=72905&id=73693#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24689

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


Index: llvm/trunk/unittests/ADT/DenseSetTest.cpp
===================================================================
--- llvm/trunk/unittests/ADT/DenseSetTest.cpp
+++ llvm/trunk/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: llvm/trunk/include/llvm/ADT/DenseSet.h
===================================================================
--- llvm/trunk/include/llvm/ADT/DenseSet.h
+++ llvm/trunk/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.73693.patch
Type: text/x-patch
Size: 2138 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161005/128f8278/attachment.bin>


More information about the llvm-commits mailing list