Browse Source

AK: Add const variant of Vector::in_reverse()

Andreas Kling 3 năm trước cách đây
mục cha
commit
fc6b7fcd97
2 tập tin đã thay đổi với 13 bổ sung4 xóa
  1. 5 4
      AK/NonnullPtrVector.h
  2. 8 0
      AK/Vector.h

+ 5 - 4
AK/NonnullPtrVector.h

@@ -32,19 +32,20 @@ public:
     using ConstIterator = SimpleIterator<const NonnullPtrVector, const T>;
     using Iterator = SimpleIterator<NonnullPtrVector, T>;
     using ReverseIterator = SimpleReverseIterator<NonnullPtrVector, T>;
+    using ReverseConstIterator = SimpleReverseIterator<NonnullPtrVector, T const>;
 
     ALWAYS_INLINE constexpr ConstIterator begin() const { return ConstIterator::begin(*this); }
     ALWAYS_INLINE constexpr Iterator begin() { return Iterator::begin(*this); }
     ALWAYS_INLINE constexpr ReverseIterator rbegin() { return ReverseIterator::rbegin(*this); }
+    ALWAYS_INLINE constexpr ReverseConstIterator rbegin() const { return ReverseConstIterator::rbegin(*this); }
 
     ALWAYS_INLINE constexpr ConstIterator end() const { return ConstIterator::end(*this); }
     ALWAYS_INLINE constexpr Iterator end() { return Iterator::end(*this); }
     ALWAYS_INLINE constexpr ReverseIterator rend() { return ReverseIterator::rend(*this); }
+    ALWAYS_INLINE constexpr ReverseConstIterator rend() const { return ReverseConstIterator::rend(*this); }
 
-    ALWAYS_INLINE constexpr auto in_reverse()
-    {
-        return ReverseWrapper::in_reverse(*this);
-    }
+    ALWAYS_INLINE constexpr auto in_reverse() { return ReverseWrapper::in_reverse(*this); }
+    ALWAYS_INLINE constexpr auto in_reverse() const { 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); }

+ 8 - 0
AK/Vector.h

@@ -702,20 +702,28 @@ public:
     using ConstIterator = SimpleIterator<Vector const, VisibleType const>;
     using Iterator = SimpleIterator<Vector, VisibleType>;
     using ReverseIterator = SimpleReverseIterator<Vector, VisibleType>;
+    using ReverseConstIterator = SimpleReverseIterator<Vector const, VisibleType const>;
 
     ConstIterator begin() const { return ConstIterator::begin(*this); }
     Iterator begin() { return Iterator::begin(*this); }
     ReverseIterator rbegin() { return ReverseIterator::rbegin(*this); }
+    ReverseConstIterator rbegin() const { return ReverseConstIterator::rbegin(*this); }
 
     ConstIterator end() const { return ConstIterator::end(*this); }
     Iterator end() { return Iterator::end(*this); }
     ReverseIterator rend() { return ReverseIterator::rend(*this); }
+    ReverseConstIterator rend() const { return ReverseConstIterator::rend(*this); }
 
     ALWAYS_INLINE constexpr auto in_reverse()
     {
         return ReverseWrapper::in_reverse(*this);
     }
 
+    ALWAYS_INLINE constexpr auto in_reverse() const
+    {
+        return ReverseWrapper::in_reverse(*this);
+    }
+
     template<typename TUnaryPredicate>
     ConstIterator find_if(TUnaryPredicate&& finder) const
     {