mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #13252 from marcemmers/span-add-begin-end
Implements iterators for the Span class to be compatible with std::spanpull/13263/head
commit
aa605bb056
101
platform/Span.h
101
platform/Span.h
|
@ -19,6 +19,7 @@
|
||||||
#define MBED_PLATFORM_SPAN_H_
|
#define MBED_PLATFORM_SPAN_H_
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <iterator>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
@ -233,6 +234,16 @@ struct Span {
|
||||||
*/
|
*/
|
||||||
typedef element_type &reference;
|
typedef element_type &reference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterator to an ElementType
|
||||||
|
*/
|
||||||
|
typedef pointer iterator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse iterator to an ElementType
|
||||||
|
*/
|
||||||
|
typedef std::reverse_iterator<iterator> reverse_iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Size of the Extent; -1 if dynamic.
|
* Size of the Extent; -1 if dynamic.
|
||||||
*/
|
*/
|
||||||
|
@ -349,6 +360,46 @@ struct Span {
|
||||||
return size() == 0;
|
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.
|
* Returns a reference to the element at position @p index.
|
||||||
*
|
*
|
||||||
|
@ -534,6 +585,16 @@ struct Span<ElementType, SPAN_DYNAMIC_EXTENT> {
|
||||||
*/
|
*/
|
||||||
typedef element_type &reference;
|
typedef element_type &reference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterator to an ElementType
|
||||||
|
*/
|
||||||
|
typedef pointer iterator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse iterator to an ElementType
|
||||||
|
*/
|
||||||
|
typedef std::reverse_iterator<iterator> reverse_iterator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Size of the Extent; -1 if dynamic.
|
* Size of the Extent; -1 if dynamic.
|
||||||
*/
|
*/
|
||||||
|
@ -644,6 +705,46 @@ struct Span<ElementType, SPAN_DYNAMIC_EXTENT> {
|
||||||
return size() == 0;
|
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.
|
* Access to an element of the sequence.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue