[PATCH] D28999: Allow DenseSet::iterators to be conveted to and compared with const_iterator
Dean Michael Berris via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 23 20:22:25 PST 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL292879: Allow DenseSet::iterators to be conveted to and compared with const_iterator (authored by dberris).
Changed prior to commit:
https://reviews.llvm.org/D28999?vs=85323&id=85522#toc
Repository:
rL LLVM
https://reviews.llvm.org/D28999
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
@@ -73,6 +73,15 @@
EXPECT_EQ(0u, set.count(3));
}
+TYPED_TEST(DenseSetTest, ConstIteratorComparison){
+ TypeParam set({1});
+ const TypeParam &cset = set;
+ EXPECT_EQ(set.begin(), cset.begin());
+ EXPECT_EQ(set.end(), cset.end());
+ EXPECT_NE(set.end(), cset.begin());
+ EXPECT_NE(set.begin(), cset.end());
+}
+
TYPED_TEST(DenseSetTest, EmptyInitializerList) {
TypeParam set({});
EXPECT_EQ(0u, set.size());
Index: llvm/trunk/include/llvm/ADT/DenseSet.h
===================================================================
--- llvm/trunk/include/llvm/ADT/DenseSet.h
+++ llvm/trunk/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() = default;
Iterator(const typename MapTy::iterator &i) : I(i) {}
ValueT &operator*() { return I->getFirst(); }
@@ -110,21 +114,26 @@
Iterator& operator++() { ++I; return *this; }
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() = default;
+
ConstIterator(const typename MapTy::const_iterator &i) : I(i) {}
const ValueT &operator*() const { return I->getFirst(); }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28999.85522.patch
Type: text/x-patch
Size: 2426 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170124/3324e3a4/attachment.bin>
More information about the llvm-commits
mailing list