Support backwards iteration starting from end().

llvm-svn: 119871
This commit is contained in:
Jakob Stoklund Olesen 2010-11-19 23:28:53 +00:00
parent 0840b75ab3
commit 328eb0d328
2 changed files with 11 additions and 1 deletions

View File

@ -1235,7 +1235,7 @@ public:
if (!branched()) {
assert(rootOffset && "Cannot decrement begin()");
--rootOffset;
} else if (treeLeafOffset())
} else if (valid() && treeLeafOffset())
--treeLeafOffset();
else
treeDecrement();

View File

@ -352,6 +352,16 @@ TEST(IntervalMapTest, Branched) {
EXPECT_FALSE(I.valid());
EXPECT_TRUE(I == map.end());
// Backwards iteration.
for (unsigned i = 99; i; --i) {
--I;
ASSERT_TRUE(I.valid());
EXPECT_EQ(10*i, I.start());
EXPECT_EQ(10*i+5, I.stop());
EXPECT_EQ(i, *I);
}
EXPECT_TRUE(I == map.begin());
}
} // namespace