Skip to content

Commit

Permalink
[ilist_node] Add a getReverseIterator() method and a unittest for it.
Browse files Browse the repository at this point in the history
This is the reverse_iterator analogue of getIterator().

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285780 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
gottesmm committed Nov 2, 2016
1 parent 772d912 commit 465b55b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/llvm/ADT/ilist_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ template <class OptionsT> class ilist_node_impl : OptionsT::node_base_type {
public:
self_iterator getIterator() { return self_iterator(*this); }
const_self_iterator getIterator() const { return const_self_iterator(*this); }
reverse_self_iterator getReverseIterator() {
return reverse_self_iterator(*this);
}
const_reverse_self_iterator getReverseIterator() const {
return const_reverse_self_iterator(*this);
}

// Under-approximation, but always available for assertions.
using node_base_type::isKnownSentinel;
Expand Down
17 changes: 17 additions & 0 deletions unittests/ADT/SimpleIListTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,23 @@ TEST(SimpleIListTest, erase) {
EXPECT_EQ(2u, L.size());
}

TEST(SimpleIListTest, reverse_iterator) {
simple_ilist<Node> L;
Node A, B, C;
L.push_back(A);
L.push_back(B);
L.push_back(C);

auto ReverseIter = L.rbegin();
EXPECT_EQ(C.getReverseIterator(), ReverseIter);
++ReverseIter;
EXPECT_EQ(B.getReverseIterator(), ReverseIter);
++ReverseIter;
EXPECT_EQ(A.getReverseIterator(), ReverseIter);
++ReverseIter;
EXPECT_EQ(L.rend(), ReverseIter);
}

TEST(SimpleIListTest, eraseAndDispose) {
simple_ilist<Node> L;
Node A, C;
Expand Down

0 comments on commit 465b55b

Please sign in to comment.