Support backwards iteration starting from end().

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119871 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jakob Stoklund Olesen 2010-11-19 23:28:53 +00:00
parent a197cba66d
commit db52566d68
2 changed files with 11 additions and 1 deletions

View File

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

View File

@ -352,6 +352,16 @@ TEST(IntervalMapTest, Branched) {
EXPECT_FALSE(I.valid()); EXPECT_FALSE(I.valid());
EXPECT_TRUE(I == map.end()); 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 } // namespace