From faf00da81c52dc17ad5565a9313c58225b7d7397 Mon Sep 17 00:00:00 2001 From: Michael Gottesman Date: Wed, 2 Nov 2016 00:59:58 +0000 Subject: [PATCH] [ilist_node] Add a getReverseIterator() method and a unittest for it. This is the reverse_iterator analogue of getIterator(). llvm-svn: 285780 --- include/llvm/ADT/ilist_node.h | 6 ++++++ unittests/ADT/SimpleIListTest.cpp | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/llvm/ADT/ilist_node.h b/include/llvm/ADT/ilist_node.h index 84208b0841b..7244d0f4058 100644 --- a/include/llvm/ADT/ilist_node.h +++ b/include/llvm/ADT/ilist_node.h @@ -80,6 +80,12 @@ private: 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; diff --git a/unittests/ADT/SimpleIListTest.cpp b/unittests/ADT/SimpleIListTest.cpp index 5a3834822d6..a354f332006 100644 --- a/unittests/ADT/SimpleIListTest.cpp +++ b/unittests/ADT/SimpleIListTest.cpp @@ -178,6 +178,23 @@ TEST(SimpleIListTest, erase) { EXPECT_EQ(2u, L.size()); } +TEST(SimpleIListTest, reverse_iterator) { + simple_ilist 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 L; Node A, C;