From dfa8ea714df17d04ed1f2034562d7f5304b5f296 Mon Sep 17 00:00:00 2001 From: Marc Emmers Date: Wed, 8 Jul 2020 17:14:39 +0200 Subject: [PATCH 1/2] Add begin, end, rbegin and rend iterator functions to Span --- platform/Span.h | 100 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/platform/Span.h b/platform/Span.h index c5bac9d682..8f542466f1 100644 --- a/platform/Span.h +++ b/platform/Span.h @@ -233,6 +233,16 @@ struct Span { */ typedef element_type &reference; + /** + * Iterator to an ElementType + */ + typedef pointer iterator; + + /** + * Reverse iterator to an ElementType + */ + typedef std::reverse_iterator reverse_iterator; + /** * Size of the Extent; -1 if dynamic. */ @@ -349,6 +359,46 @@ struct Span { return size() == 0; } + /** + * Return an iterator to the first element of the sequence. + * + * @return An iterator to the first element of the sequence. + */ + iterator begin() const + { + return _data; + } + + /** + * Return an iterator to the element following the last element of the sequence. + * + * @return An iterator to the element following the last element of the sequence. + */ + iterator end() const + { + return _data + Extent; + } + + /** + * Return a reverse_iterator to the first element of the reversed sequence. + * + * @return A reverse_iterator to the first element of the reversed sequence. + */ + reverse_iterator rbegin() const + { + return reverse_iterator(end()); + } + + /** + * Return a reverse_iterator to the element following the last element of the reversed sequence. + * + * @return A reverse_iterator to the element following the last element of the reversed sequence. + */ + reverse_iterator rend() const + { + return reverse_iterator(begin()); + } + /** * Returns a reference to the element at position @p index. * @@ -534,6 +584,16 @@ struct Span { */ typedef element_type &reference; + /** + * Iterator to an ElementType + */ + typedef pointer iterator; + + /** + * Reverse iterator to an ElementType + */ + typedef std::reverse_iterator reverse_iterator; + /** * Size of the Extent; -1 if dynamic. */ @@ -644,6 +704,46 @@ struct Span { return size() == 0; } + /** + * Return an iterator to the first element of the sequence. + * + * @return An iterator to the first element of the sequence. + */ + iterator begin() const + { + return _data; + } + + /** + * Return an iterator to the element following the last element of the sequence. + * + * @return An iterator to the element following the last element of the sequence. + */ + iterator end() const + { + return _data + _size; + } + + /** + * Return a reverse_iterator to the first element of the reversed sequence. + * + * @return A reverse_iterator to the first element of the reversed sequence. + */ + reverse_iterator rbegin() const + { + return reverse_iterator(end()); + } + + /** + * Return a reverse_iterator to the element following the last element of the reversed sequence. + * + * @return A reverse_iterator to the element following the last element of the reversed sequence. + */ + reverse_iterator rend() const + { + return reverse_iterator(begin()); + } + /** * Access to an element of the sequence. * From a20ff63574243e9e2f385b7d2573b7150e5521fa Mon Sep 17 00:00:00 2001 From: Marc Emmers Date: Thu, 9 Jul 2020 12:23:00 +0200 Subject: [PATCH 2/2] Add include --- platform/Span.h | 1 + 1 file changed, 1 insertion(+) diff --git a/platform/Span.h b/platform/Span.h index 8f542466f1..450b7f57a1 100644 --- a/platform/Span.h +++ b/platform/Span.h @@ -19,6 +19,7 @@ #define MBED_PLATFORM_SPAN_H_ #include +#include #include #include