[libcamera-devel] [PATCH 2/2] libcamera: span: Fix reverse iterators
Laurent Pinchart
laurent.pinchart at ideasonboard.com
Tue Apr 13 02:27:31 CEST 2021
std::reverse_iterator<iterator> is constructed from an instance of
iterator, and automatically subtract 1 when dereferencing. rbegin() and
rend() should thus be constructed from end() and begin() respectively.
Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
include/libcamera/span.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/libcamera/span.h b/include/libcamera/span.h
index 91e9f974cc58..7a35806b1710 100644
--- a/include/libcamera/span.h
+++ b/include/libcamera/span.h
@@ -194,9 +194,9 @@ public:
constexpr const_iterator cbegin() const { return begin(); }
constexpr iterator end() const { return data() + size(); }
constexpr const_iterator cend() const { return end(); }
- constexpr reverse_iterator rbegin() const { return reverse_iterator(data() + size() - 1); }
+ constexpr reverse_iterator rbegin() const { return reverse_iterator(end()); }
constexpr const_reverse_iterator crbegin() const { return rbegin(); }
- constexpr reverse_iterator rend() const { return reverse_iterator(data() - 1); }
+ constexpr reverse_iterator rend() const { return reverse_iterator(begin()); }
constexpr const_reverse_iterator crend() const { return rend(); }
constexpr reference front() const { return *data(); }
@@ -360,9 +360,9 @@ public:
constexpr const_iterator cbegin() const { return begin(); }
constexpr iterator end() const { return data() + size(); }
constexpr const_iterator cend() const { return end(); }
- constexpr reverse_iterator rbegin() const { return reverse_iterator(data() + size() - 1); }
+ constexpr reverse_iterator rbegin() const { return reverse_iterator(end()); }
constexpr const_reverse_iterator crbegin() const { return rbegin(); }
- constexpr reverse_iterator rend() const { return reverse_iterator(data() - 1); }
+ constexpr reverse_iterator rend() const { return reverse_iterator(begin()); }
constexpr const_reverse_iterator crend() const { return rend(); }
constexpr reference front() const { return *data(); }
--
Regards,
Laurent Pinchart
More information about the libcamera-devel
mailing list