18 #ifndef MBED_PLATFORM_SPAN_H_    19 #define MBED_PLATFORM_SPAN_H_    26 #include "platform/mbed_assert.h"    40 namespace span_detail {
    44 template<
typename From, 
typename To>
    49     struct false_type { };
    51     static const From &generator();
    52     static true_type sink(
const To &);
    53     static false_type sink(...);
    56     static const bool value = 
sizeof(true_type) == 
sizeof(sink(generator()));
    61 #if defined(DOXYGEN_ONLY)    69 const ptrdiff_t SPAN_DYNAMIC_EXTENT = -1;
    71 #define SPAN_DYNAMIC_EXTENT -1   214 template<
typename ElementType, ptrdiff_t Extent = SPAN_DYNAMIC_EXTENT>
   250     static const index_type extent = Extent;
   252     static_assert(Extent >= 0, 
"Invalid extent for a Span");
   267             "Cannot default construct a static-extent Span (unless Extent is 0)"   283     Span(pointer ptr, index_type count) :
   302     Span(pointer first, pointer last) :
   320     Span(element_type (&elements)[Extent]):
   332     template<
typename OtherElementType>
   338             "OtherElementType(*)[] should be convertible to ElementType (*)[]"   380         return _data + Extent;
   390         return reverse_iterator(end());
   400         return reverse_iterator(begin());
   440     template<ptrdiff_t Count>
   444             (0 <= Count) && (Count <= Extent),
   445             "Invalid subspan extent"   459     template<ptrdiff_t Count>
   463             (0 <= Count) && (Count <= Extent),
   464             "Invalid subspan extent"   483     template<std::ptrdiff_t Offset, std::ptrdiff_t Count>
   484     Span<element_type, Count == SPAN_DYNAMIC_EXTENT ? Extent - Offset : Count>
   488             0 <= Offset && Offset <= Extent,
   489             "Invalid subspan offset"   492             (Count == SPAN_DYNAMIC_EXTENT) ||
   493             (0 <= Count && (Count + Offset) <= Extent),
   494             "Invalid subspan count"   496         return Span<element_type, Count == SPAN_DYNAMIC_EXTENT ? Extent - Offset : Count>(
   498             Count == SPAN_DYNAMIC_EXTENT ? Extent - Offset : Count
   527                    _data + (Extent - count),
   545         index_type offset, index_type count = SPAN_DYNAMIC_EXTENT
   550             (count == SPAN_DYNAMIC_EXTENT) ||
   551             (0 <= count && (count + offset) <= Extent)
   555                    count == SPAN_DYNAMIC_EXTENT ? Extent - offset : count
   566 template<
typename ElementType>
   567 struct Span<ElementType, SPAN_DYNAMIC_EXTENT> {
   601     static const index_type extent = SPAN_DYNAMIC_EXTENT;
   612         _data(NULL), _size(0) { }
   626     Span(pointer ptr, index_type count) :
   627         _data(ptr), _size(count)
   645     Span(pointer first, pointer last) :
   646         _data(first), _size(last - first)
   664     template<
size_t Count>
   665     Span(element_type (&elements)[Count]):
   666         _data(elements), _size(Count) { }
   677     template<
typename OtherElementType, ptrdiff_t OtherExtent>
   679         _data(other.data()), _size(other.size())
   683             "OtherElementType(*)[] should be convertible to ElementType (*)[]"   725         return _data + _size;
   735         return reverse_iterator(end());
   745         return reverse_iterator(begin());
   784     template<ptrdiff_t Count>
   800     template<ptrdiff_t Count>
   819     template<std::ptrdiff_t Offset, std::ptrdiff_t Count>
   825             (Count == SPAN_DYNAMIC_EXTENT) ||
   826             (0 <= Count && (Count + Offset) <= _size)
   830                    Count == SPAN_DYNAMIC_EXTENT ? _size - Offset : Count
   858                    _data + (_size - count),
   876         index_type offset, index_type count = SPAN_DYNAMIC_EXTENT
   881             (count == SPAN_DYNAMIC_EXTENT) ||
   882             (0 <= count && (count + offset) <= _size)
   886                    count == SPAN_DYNAMIC_EXTENT ? _size - offset : count
   906 template<
typename T, 
typename U, ptrdiff_t LhsExtent, ptrdiff_t RhsExtent>
   931 template<
typename T, ptrdiff_t LhsExtent, ptrdiff_t RhsExtent>
   946 template<
typename T, ptrdiff_t LhsExtent, ptrdiff_t RhsExtent>
   963 template<
typename T, 
typename U, ptrdiff_t LhsExtent, ptrdiff_t RhsExtent>
   966     return !(lhs == rhs);
   978 template<
typename T, ptrdiff_t LhsExtent, ptrdiff_t RhsExtent>
   993 template<
typename T, ptrdiff_t LhsExtent, ptrdiff_t RhsExtent>
  1014 template<
typename T, 
size_t Size>
  1033 template<ptrdiff_t Extent, 
typename T>
  1054 template<
typename T>
  1057     return Span<T>(array_ptr, array_size);
  1072 template<
typename T, 
size_t Extent>
  1093 template<
size_t Extent, 
typename T>
  1115 template<
typename T>
 Span< element_type, Count > last() const 
Create a new Span over the last Count elements of the existing view. 
ElementType element_type
Type of the element contained. 
index_type size() const 
Return the size of the sequence viewed. 
iterator end() const 
Return an iterator to the element following the last element of the sequence. 
index_type size() const 
Return the size of the array viewed. 
Span()
Construct an empty Span. 
Span< element_type, SPAN_DYNAMIC_EXTENT > first(index_type count) const 
Create a new Span over the first count elements of the existing view. 
pointer data() const 
Get the raw pointer to the sequence viewed. 
Span< element_type, SPAN_DYNAMIC_EXTENT > last(index_type count) const 
Create a new Span over the last count elements of the existing view. 
iterator begin() const 
Return an iterator to the first element of the sequence. 
Span< element_type, Count > first() const 
Create a new Span over the first Count elements of the existing view. 
Span< element_type, SPAN_DYNAMIC_EXTENT > subspan(index_type offset, index_type count=SPAN_DYNAMIC_EXTENT) const 
Create a subspan that is a view of other count elements; the view starts at element offset...
reverse_iterator rbegin() const 
Return a reverse_iterator to the first element of the reversed sequence. 
Span< element_type, Count==SPAN_DYNAMIC_EXTENT?Extent-Offset:Count > subspan() const 
Create a subspan that is a view of other Count elements; the view starts at element Offset...
iterator end() const 
Return an iterator to the element following the last element of the sequence. 
std::reverse_iterator< iterator > reverse_iterator
Reverse iterator to an ElementType. 
ptrdiff_t index_type
Type of the index. 
Span< element_type, Count > first() const 
Create a new Span over the first Count elements of the existing view. 
reverse_iterator rend() const 
Return a reverse_iterator to the element following the last element of the reversed sequence...
reference operator[](index_type index) const 
Access to an element of the sequence. 
element_type & reference
Reference to an ElementType. 
Span< element_type, SPAN_DYNAMIC_EXTENT > last(index_type count) const 
Create a new Span over the last count elements of the existing view. 
Span(pointer ptr, index_type count)
Construct a Span from a pointer to a buffer and its size. 
Span()
Construct an empty Span. 
element_type * pointer
Pointer to an ElementType. 
ptrdiff_t index_type
Type of the index. 
reverse_iterator rbegin() const 
Return a reverse_iterator to the first element of the reversed sequence. 
element_type & reference
Reference to an ElementType. 
Span< element_type, Count > subspan() const 
Create a subspan that is a view other Count elements; the view starts at element Offset. 
reverse_iterator rend() const 
Return a reverse_iterator to the element following the last element of the reversed sequence...
Span(pointer first, pointer last)
Construct a Span from the range [first, last). 
element_type * pointer
Pointer to an ElementType. 
ElementType element_type
Type of the element contained. 
iterator begin() const 
Return an iterator to the first element of the sequence. 
Span(pointer first, pointer last)
Construct a Span from the range [first, last). 
pointer iterator
Iterator to an ElementType. 
Span< element_type, Count > last() const 
Create a new Span over the last Count elements of the existing view. 
Nonowning view to a sequence of contiguous elements. 
Span< element_type, SPAN_DYNAMIC_EXTENT > first(index_type count) const 
Create a new Span over the first count elements of the existing view. 
Span(const Span< OtherElementType, OtherExtent > &other)
Construct a Span object from another Span. 
void operator!=(const SafeBool< T > &lhs, const SafeBool< U > &rhs)
Avoid conversion to bool between different classes. 
Span< element_type, SPAN_DYNAMIC_EXTENT > subspan(index_type offset, index_type count=SPAN_DYNAMIC_EXTENT) const 
Create a subspan that is a view of other count elements; the view starts at element offset...
void operator==(const SafeBool< T > &lhs, const SafeBool< U > &rhs)
Avoid conversion to bool between different classes. 
bool empty() const 
Return if the sequence viewed is empty or not. 
Span(pointer ptr, index_type count)
Construct a Span from a pointer to a buffer and its size. 
bool empty() const 
Return if the sequence is empty or not. 
std::reverse_iterator< iterator > reverse_iterator
Reverse iterator to an ElementType. 
pointer data() const 
Return a pointer to the first element of the sequence or NULL if the Span is empty(). 
Span(element_type(&elements)[Extent])
Construct a Span from the reference to an array. 
Span(element_type(&elements)[Count])
Construct a Span from the reference to an array. 
reference operator[](index_type index) const 
Returns a reference to the element at position index. 
pointer iterator
Iterator to an ElementType. 
Span(const Span< OtherElementType, Extent > &other)
Construct a Span object from another Span of the same size.