summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/ADT/IListIteratorTest.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2017-02-07 21:03:50 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2017-02-07 21:03:50 +0000
commitfcd69daaa14099e350e937ec4575445b78a72c6c (patch)
tree1d1aa3bfc7409235a812b291a6619cc5ad294231 /llvm/unittests/ADT/IListIteratorTest.cpp
parent819e3e02a9d4e2b0e986c5d2cfe13f138cff17cc (diff)
downloadbcm5719-llvm-fcd69daaa14099e350e937ec4575445b78a72c6c.tar.gz
bcm5719-llvm-fcd69daaa14099e350e937ec4575445b78a72c6c.zip
ADT: Add explicit conversions for reverse ilist iterators
Add explicit conversions between forward and reverse ilist iterators. These follow the conversion conventions of std::reverse_iterator, which are off-by-one: the newly-constructed "reverse" iterator dereferences to the previous node of the one sent in. This has the benefit of converting reverse ranges in place: - If [I, E) is a valid range, - then [reverse(E), reverse(I)) gives the same range in reverse order. ilist_iterator::getReverse() is unchanged: it returns a reverse iterator to the *same* node. llvm-svn: 294349
Diffstat (limited to 'llvm/unittests/ADT/IListIteratorTest.cpp')
-rw-r--r--llvm/unittests/ADT/IListIteratorTest.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/llvm/unittests/ADT/IListIteratorTest.cpp b/llvm/unittests/ADT/IListIteratorTest.cpp
index ddcab781b9b..7e066c2373a 100644
--- a/llvm/unittests/ADT/IListIteratorTest.cpp
+++ b/llvm/unittests/ADT/IListIteratorTest.cpp
@@ -131,4 +131,44 @@ TEST(IListIteratorTest, CheckEraseReverse) {
EXPECT_EQ(L.rend(), RI);
}
+TEST(IListIteratorTest, ReverseConstructor) {
+ simple_ilist<Node> L;
+ const simple_ilist<Node> &CL = L;
+ Node A, B;
+ L.insert(L.end(), A);
+ L.insert(L.end(), B);
+
+ // Save typing.
+ typedef simple_ilist<Node>::iterator iterator;
+ typedef simple_ilist<Node>::reverse_iterator reverse_iterator;
+ typedef simple_ilist<Node>::const_iterator const_iterator;
+ typedef simple_ilist<Node>::const_reverse_iterator const_reverse_iterator;
+
+ // Check conversion values.
+ EXPECT_EQ(L.begin(), iterator(L.rend()));
+ EXPECT_EQ(++L.begin(), iterator(++L.rbegin()));
+ EXPECT_EQ(L.end(), iterator(L.rbegin()));
+ EXPECT_EQ(L.rbegin(), reverse_iterator(L.end()));
+ EXPECT_EQ(++L.rbegin(), reverse_iterator(++L.begin()));
+ EXPECT_EQ(L.rend(), reverse_iterator(L.begin()));
+
+ // Check const iterator constructors.
+ EXPECT_EQ(CL.begin(), const_iterator(L.rend()));
+ EXPECT_EQ(CL.begin(), const_iterator(CL.rend()));
+ EXPECT_EQ(CL.rbegin(), const_reverse_iterator(L.end()));
+ EXPECT_EQ(CL.rbegin(), const_reverse_iterator(CL.end()));
+
+ // Confirm lack of implicit conversions.
+ static_assert(std::is_convertible<iterator, reverse_iterator>::value,
+ "unexpected implicit conversion");
+ static_assert(std::is_convertible<reverse_iterator, iterator>::value,
+ "unexpected implicit conversion");
+ static_assert(
+ std::is_convertible<const_iterator, const_reverse_iterator>::value,
+ "unexpected implicit conversion");
+ static_assert(
+ std::is_convertible<const_reverse_iterator, const_iterator>::value,
+ "unexpected implicit conversion");
+}
+
} // end namespace
OpenPOWER on IntegriCloud