Allow DenseSet::iterators to be conveted to and compared with const_iterator
Summary:
This seemed to be an oversight seeing as DenseMap has these conversions.
This patch does the following:
- Adds a default constructor to the iterators.
- Allows DenseSet::ConstIterators to be copy constructed from DenseSet::Iterators
- Allows mutual comparison between Iterators and ConstIterators.
All of these are available in the DenseMap implementation, so the implementation here is trivial.
Reviewers: dblaikie, dberris
Reviewed By: dberris
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D28999
llvm-svn: 292879
diff --git a/llvm/unittests/ADT/DenseSetTest.cpp b/llvm/unittests/ADT/DenseSetTest.cpp
index 4d5a829..4b15974 100644
--- a/llvm/unittests/ADT/DenseSetTest.cpp
+++ b/llvm/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());