[PATCH] D28999: Allow DenseSet::iterators to be conveted to and compared with const_iterator

Alexis Shaw via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 22 19:23:57 PST 2017


varno created this revision.

This seemed to be an oversight seeing as DenseMap has these conversions.


https://reviews.llvm.org/D28999

Files:
  include/llvm/ADT/DenseSet.h


Index: include/llvm/ADT/DenseSet.h
===================================================================
--- include/llvm/ADT/DenseSet.h
+++ include/llvm/ADT/DenseSet.h
@@ -90,17 +90,21 @@
 
   // Iterators.
 
+  class ConstIterator;
+
   class Iterator {
     typename MapTy::iterator I;
     friend class DenseSetImpl;
+    friend class ConstIterator;
 
   public:
     typedef typename MapTy::iterator::difference_type difference_type;
     typedef ValueT value_type;
     typedef value_type *pointer;
     typedef value_type &reference;
     typedef std::forward_iterator_tag iterator_category;
 
+    Iterator() {};
     Iterator(const typename MapTy::iterator &i) : I(i) {}
 
     ValueT &operator*() { return I->getFirst(); }
@@ -112,19 +116,27 @@
     Iterator operator++(int) { auto T = *this; ++I; return T; }
     bool operator==(const Iterator& X) const { return I == X.I; }
     bool operator!=(const Iterator& X) const { return I != X.I; }
+
+    bool operator==(const ConstIterator& X) const { return I == X.I; }
+    bool operator!=(const ConstIterator& X) const { return I == X.I; }
   };
 
   class ConstIterator {
     typename MapTy::const_iterator I;
     friend class DenseSet;
+    friend class Iterator;
 
   public:
     typedef typename MapTy::const_iterator::difference_type difference_type;
     typedef ValueT value_type;
     typedef value_type *pointer;
     typedef value_type &reference;
     typedef std::forward_iterator_tag iterator_category;
 
+    ConstIterator(const Iterator &B) : I(B.I) {}
+
+    ConstIterator() {};
+
     ConstIterator(const typename MapTy::const_iterator &i) : I(i) {}
 
     const ValueT &operator*() const { return I->getFirst(); }
@@ -134,6 +146,9 @@
     ConstIterator operator++(int) { auto T = *this; ++I; return T; }
     bool operator==(const ConstIterator& X) const { return I == X.I; }
     bool operator!=(const ConstIterator& X) const { return I != X.I; }
+
+    bool operator==(const Iterator& X) const { return I == X.I; }
+    bool operator!=(const Iterator& X) const { return I != X.I; }
   };
 
   typedef Iterator      iterator;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28999.85311.patch
Type: text/x-patch
Size: 2106 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170123/d251f1a4/attachment.bin>


More information about the llvm-commits mailing list