[PATCH] D27874: ilist_iterator: Allow conversion between reverse and forward iterators
Matthias Braun via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 16 18:39:35 PST 2016
MatzeB created this revision.
MatzeB added a reviewer: dexonsmith.
MatzeB added a subscriber: llvm-commits.
MatzeB set the repository for this revision to rL LLVM.
Herald added a subscriber: mcrosier.
Repository:
rL LLVM
https://reviews.llvm.org/D27874
Files:
include/llvm/ADT/ilist_iterator.h
unittests/ADT/SimpleIListTest.cpp
Index: unittests/ADT/SimpleIListTest.cpp
===================================================================
--- unittests/ADT/SimpleIListTest.cpp
+++ unittests/ADT/SimpleIListTest.cpp
@@ -193,6 +193,20 @@
EXPECT_EQ(A.getReverseIterator(), ReverseIter);
++ReverseIter;
EXPECT_EQ(L.rend(), ReverseIter);
+
+ // Check conversion between reverse/forward iterators.
+ typedef simple_ilist<Node>::reverse_iterator reverse_iterator;
+ typedef simple_ilist<Node>::iterator iterator;
+ EXPECT_EQ(reverse_iterator(L.begin()), std::prev(L.rend()));
+ EXPECT_EQ(reverse_iterator(std::prev(L.end())), L.rbegin());
+ EXPECT_EQ(iterator(L.rbegin()), std::prev(L.end()));
+ EXPECT_EQ(iterator(std::prev(L.rend())), L.begin());
+ for (Node &N : L) {
+ EXPECT_EQ(iterator(reverse_iterator(N.getIterator())),
+ N.getIterator());
+ EXPECT_EQ(reverse_iterator(iterator(N.getReverseIterator())),
+ N.getReverseIterator());
+ }
}
TEST(SimpleIListTest, eraseAndDispose) {
Index: include/llvm/ADT/ilist_iterator.h
===================================================================
--- include/llvm/ADT/ilist_iterator.h
+++ include/llvm/ADT/ilist_iterator.h
@@ -86,10 +86,10 @@
ilist_iterator() : NodePtr(nullptr) {}
// This is templated so that we can allow constructing a const iterator from
- // a nonconst iterator...
- template <bool RHSIsConst>
+ // a nonconst iterator and switch between reverse/forward iterators...
+ template <bool RHSIsConst, bool RHSIsReverse>
ilist_iterator(
- const ilist_iterator<OptionsT, IsReverse, RHSIsConst> &RHS,
+ const ilist_iterator<OptionsT, RHSIsReverse, RHSIsConst> &RHS,
typename std::enable_if<IsConst || !RHSIsConst, void *>::type = nullptr)
: NodePtr(RHS.NodePtr) {}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27874.81832.patch
Type: text/x-patch
Size: 1785 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161217/b400c7bb/attachment.bin>
More information about the llvm-commits
mailing list