Add default constructors for iterators.
authorJakob Stoklund Olesen <stoklund@2pi.dk>
Sun, 28 Nov 2010 07:21:48 +0000 (07:21 +0000)
committerJakob Stoklund Olesen <stoklund@2pi.dk>
Sun, 28 Nov 2010 07:21:48 +0000 (07:21 +0000)
These iterators don't point anywhere, and they can't be compared to anything.
They are only good for assigning to.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120239 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/IntervalMap.h
unittests/ADT/IntervalMapTest.cpp

index bf8dee6f3aece9bfd25ef423c17f249a25221a97..2bd885cf8a70f35df72b1c167766c218ec9ed956 100644 (file)
@@ -1397,6 +1397,9 @@ protected:
   void treeAdvanceTo(KeyT x);
 
 public:
+  /// const_iterator - Create an iterator that isn't pointing anywhere.
+  const_iterator() : map(0) {}
+
   /// valid - Return true if the current position is valid, false for end().
   bool valid() const { return path.valid(); }
 
@@ -1583,6 +1586,9 @@ class IntervalMap<KeyT, ValT, N, Traits>::iterator : public const_iterator {
   void eraseNode(unsigned Level);
   void treeErase(bool UpdateRoot = true);
 public:
+  /// iterator - Create null iterator.
+  iterator() {}
+
   /// insert - Insert mapping [a;b] -> y before the current position.
   void insert(KeyT a, KeyT b, ValT y);
 
index f4b1ebc8d3a86c9034a76df4efb8a585f284962f..6b8e761ae70f1ef4a014c249aae36ddf8d6ee42f 100644 (file)
@@ -41,6 +41,14 @@ TEST(IntervalMapTest, EmptyMap) {
   UUMap::iterator I = map.begin();
   EXPECT_FALSE(I.valid());
   EXPECT_TRUE(I == map.end());
+
+  // Default constructor and cross-constness compares.
+  UUMap::const_iterator CI;
+  CI = map.begin();
+  EXPECT_TRUE(CI == I);
+  UUMap::iterator I2;
+  I2 = map.end();
+  EXPECT_TRUE(I2 == CI);
 }
 
 // Single entry map tests