summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AK/NonnullPtrVector.h5
-rw-r--r--AK/Vector.h5
-rw-r--r--Tests/AK/TestVector.cpp4
3 files changed, 14 insertions, 0 deletions
diff --git a/AK/NonnullPtrVector.h b/AK/NonnullPtrVector.h
index 728d37314d..c628196c1a 100644
--- a/AK/NonnullPtrVector.h
+++ b/AK/NonnullPtrVector.h
@@ -41,6 +41,11 @@ public:
ALWAYS_INLINE constexpr Iterator end() { return Iterator::end(*this); }
ALWAYS_INLINE constexpr ReverseIterator rend() { return ReverseIterator::rend(*this); }
+ ALWAYS_INLINE constexpr auto in_reverse()
+ {
+ return ReverseWrapper::in_reverse(*this);
+ }
+
ALWAYS_INLINE PtrType& ptr_at(size_t index) { return Base::at(index); }
ALWAYS_INLINE const PtrType& ptr_at(size_t index) const { return Base::at(index); }
diff --git a/AK/Vector.h b/AK/Vector.h
index bc4eb553dd..9c81689d80 100644
--- a/AK/Vector.h
+++ b/AK/Vector.h
@@ -704,6 +704,11 @@ public:
Iterator end() { return Iterator::end(*this); }
ReverseIterator rend() { return ReverseIterator::rend(*this); }
+ ALWAYS_INLINE constexpr auto in_reverse()
+ {
+ return ReverseWrapper::in_reverse(*this);
+ }
+
template<typename TUnaryPredicate>
ConstIterator find_if(TUnaryPredicate&& finder) const
{
diff --git a/Tests/AK/TestVector.cpp b/Tests/AK/TestVector.cpp
index fe10b017cf..74038f3788 100644
--- a/Tests/AK/TestVector.cpp
+++ b/Tests/AK/TestVector.cpp
@@ -567,4 +567,8 @@ TEST_CASE(reverse_range_for_loop)
int index = 9;
for (auto item : AK::ReverseWrapper::in_reverse(v))
EXPECT_EQ(item, index--);
+
+ index = 9;
+ for (auto item : v.in_reverse())
+ EXPECT_EQ(item, index--);
}