31#ifndef ETL_SPAN_INCLUDED
32#define ETL_SPAN_INCLUDED
45#include "static_assert.h"
49#if ETL_USING_CPP20 && ETL_USING_STL
61 template <
typename T,
size_t Extent = etl::dynamic_extent>
76 typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
77 typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
87 template <
typename TIterator,
typename TSize>
96 template <
typename TIterator>
105 template<
size_t Array_Size>
116 template <
typename TContainer,
typename =
typename etl::enable_if<!etl::is_po
inter<etl::remove_reference_t<TContainer>>::value &&
117 !etl::is_array<etl::remove_reference_t<TContainer>>::value&&
118 etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<
typename etl::remove_reference_t<TContainer>::value_type>>::value,
void>::type>
128 template <
typename TContainer>
140 template <
typename TContainer>
153 : pbegin(
other.pbegin)
160 template <
typename U,
size_t N>
162 : pbegin(
other.data())
179 return *((pbegin +
Extent) - 1);
233 ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crbegin()
const ETL_NOEXCEPT
235 return const_reverse_iterator((pbegin +
Extent));
241 ETL_NODISCARD ETL_CONSTEXPR reverse_iterator rbegin() const ETL_NOEXCEPT
243 return reverse_iterator((pbegin + Extent));
257 ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator
crend()
const ETL_NOEXCEPT
259 return const_reverse_iterator(pbegin);
265 ETL_NODISCARD ETL_CONSTEXPR reverse_iterator
rend()
const ETL_NOEXCEPT
267 return reverse_iterator(pbegin);
281 ETL_NODISCARD ETL_CONSTEXPR
size_t size()
const ETL_NOEXCEPT
307 pbegin =
other.pbegin;
342 template <
size_t COUNT>
346 ETL_STATIC_ASSERT((
Extent != etl::dynamic_extent) ?
COUNT <=
Extent :
true,
"Original span does not contain COUNT elements");
362 template <
size_t COUNT>
366 ETL_STATIC_ASSERT((
Extent != etl::dynamic_extent) ?
COUNT <=
Extent :
true,
"Original span does not contain COUNT elements");
383 template <
size_t OFFSET,
size_t COUNT = etl::dynamic_extent>
384 ETL_NODISCARD ETL_CONSTEXPR
388 ETL_STATIC_ASSERT((
Extent != etl::dynamic_extent) ?
OFFSET <=
Extent : true,
"OFFSET is not within the original span");
391 ETL_STATIC_ASSERT((
Extent != etl::dynamic_extent) && (
COUNT != etl::dynamic_extent) ?
COUNT <= (
Extent -
OFFSET) : true,
"OFFSET + COUNT is not within the original span");
400 template <
size_t OFFSET,
size_t COUNT>
404 ETL_STATIC_ASSERT((
Extent != etl::dynamic_extent) ?
OFFSET <=
Extent :
true,
"OFFSET is not within the original span");
407 ETL_STATIC_ASSERT((
Extent != etl::dynamic_extent) && (
COUNT != etl::dynamic_extent) ?
COUNT <= (
Extent -
OFFSET) :
true,
"OFFSET + COUNT is not within the original span");
409 if (
COUNT == etl::dynamic_extent)
438 template <
typename T,
size_t Extent>
447 template <
typename T>
462 typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
463 typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
468 static ETL_CONSTANT
size_t extent = etl::dynamic_extent;
473 ETL_CONSTEXPR
span() ETL_NOEXCEPT
474 : pbegin(ETL_NULLPTR)
482 template <
typename TIterator,
typename TSize>
492 template <
typename TIterator>
502 template<
size_t Array_Size>
505 , pend(
begin_ + Array_Size)
514 template <
typename TContainer,
typename =
typename etl::enable_if<!etl::is_po
inter<etl::remove_reference_t<TContainer>>::value &&
515 !etl::is_array<etl::remove_reference_t<TContainer>>::value &&
516 etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<
typename etl::remove_reference_t<TContainer>::value_type>>::value,
void>::type>
519 , pend(a.data() + a.size())
527 template <
typename TContainer>
540 template <
typename TContainer>
554 : pbegin(
other.pbegin)
562 template <
typename U,
size_t N>
564 : pbegin(
other.data())
644 ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crbegin() const ETL_NOEXCEPT
646 return const_reverse_iterator(pend);
660 ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator
crend()
const ETL_NOEXCEPT
662 return const_reverse_iterator(pbegin);
668 ETL_NODISCARD ETL_CONSTEXPR reverse_iterator
rend()
const ETL_NOEXCEPT
670 return reverse_iterator(pbegin);
678 return (pbegin == pend);
684 ETL_NODISCARD ETL_CONSTEXPR
size_t size()
const ETL_NOEXCEPT
686 return (pend - pbegin);
710 pbegin =
other.pbegin;
746 template <
size_t COUNT>
763 template <
size_t COUNT>
781 template <
size_t OFFSET,
size_t COUNT = etl::dynamic_extent>
782 ETL_NODISCARD ETL_CONSTEXPR
792 template <
size_t OFFSET,
size_t COUNT>
795 if (
COUNT == etl::dynamic_extent)
825 template <
typename T>
835 template <
typename T>
841 template <
typename T,
size_t Extent>
842 ETL_CONSTANT
size_t span<T, Extent>::extent;
844 template <
typename T>
845 ETL_CONSTANT
size_t span<T, etl::dynamic_extent>::extent;
850 template <
typename T1,
size_t N1,
typename T2,
size_t N2>
856 return (
lhs.begin() ==
rhs.begin()) && (
lhs.size() ==
rhs.size());
862 template <
typename T1,
size_t N1,
typename T2,
size_t N2>
878 template <
typename T1,
size_t N1,
typename T2,
size_t N2>
882 return (
lhs.empty() &&
rhs.empty()) ||
883 ((
lhs.begin() ==
rhs.begin()) && (
lhs.size() ==
rhs.size())) ||
884 etl::equal(
lhs.begin(),
lhs.end(),
rhs.begin(),
rhs.end());
891 template <
typename TIterator>
892 span(
const TIterator begin_,
const TIterator end_)
895 template <
typename TIterator,
typename TSize>
896 span(
const TIterator begin_,
const TSize size_)
899 template <
typename T,
size_t N>
903 template <
typename T,
size_t N>
907 template <
typename T,
size_t N>
911#if ETL_USING_STL && ETL_USING_CPP11
912 template <
typename T,
size_t N>
913 span(std::array<T, N>&)
916 template <
typename T,
size_t N>
917 span(
const std::array<T, N>&)
925#if ETL_USING_8BIT_TYPES
926 template <
typename T,
size_t Extent>
927 struct hash<
etl::span<T, Extent> >
931 return etl::private_hash::generic_hash<size_t>(
reinterpret_cast<const uint8_t*
>(view.data()),
932 reinterpret_cast<const uint8_t*
>(view.data() + view.size()));
940 template <
class T,
size_t N>
941 span<
const byte, (N == etl::dynamic_extent) ? (etl::dynamic_extent) : (N *
sizeof(T))>
950 template <
class T,
size_t N>
951 span<byte, (N == etl::dynamic_extent) ? (etl::dynamic_extent) : (N *
sizeof(T))>
Definition iterator.h:228
ETL_NODISCARD ETL_CONSTEXPR circular_iterator begin_circular() const ETL_NOEXCEPT
Returns a circular iterator to the beginning of the span.
Definition span.h:612
ETL_CONSTEXPR span(const span &other) ETL_NOEXCEPT
Copy constructor.
Definition span.h:553
ETL_CONSTEXPR span() ETL_NOEXCEPT
Default constructor.
Definition span.h:473
etl::span< element_type, COUNT !=etl::dynamic_extent ? COUNT :etl::dynamic_extent > subspan() const
Obtains a span that is a view from OFFSET over the next COUNT elements of this span.
Definition span.h:793
ETL_NODISCARD ETL_CONSTEXPR reverse_circular_iterator rbegin_circular() const ETL_NOEXCEPT
Returns a reverse circular iterator to the end of the span.
Definition span.h:652
ETL_NODISCARD ETL_CONSTEXPR etl::span< element_type, COUNT > first() const ETL_NOEXCEPT
Obtains a span that is a view over the first COUNT elements of this span.
Definition span.h:747
ETL_CONSTEXPR span(TContainer &a, typename etl::enable_if<!etl::is_pointer< typename etl::remove_reference< TContainer >::type >::value &&!etl::is_array< TContainer >::value &&etl::is_same< typename etl::remove_cv< T >::type, typename etl::remove_cv< typename etl::remove_reference< TContainer >::type::value_type >::type >::value, void >::type *=0) ETL_NOEXCEPT
Definition span.h:528
ETL_NODISCARD ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
Returns the size of the span.
Definition span.h:684
ETL_CONSTEXPR span(const etl::span< U, N > &other) ETL_NOEXCEPT
Copy constructor.
Definition span.h:563
ETL_NODISCARD ETL_CONSTEXPR14 etl::span< element_type, etl::dynamic_extent > subspan(size_t offset, size_t count=etl::dynamic_extent) const ETL_NOEXCEPT
Obtains a span that is a view from 'offset' over the next 'count' elements of this span.
Definition span.h:809
ETL_NODISCARD ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
Returns true if the span size is zero.
Definition span.h:676
ETL_NODISCARD ETL_CONSTEXPR etl::span< element_type, COUNT > last() const ETL_NOEXCEPT
Obtains a span that is a view over the last COUNT elements of this span.
Definition span.h:764
ETL_NODISCARD ETL_CONSTEXPR etl::span< element_type, etl::dynamic_extent > first(size_t count) const ETL_NOEXCEPT
Obtains a span that is a view over the first count elements of this span.
Definition span.h:755
ETL_NODISCARD ETL_CONSTEXPR reference back() const ETL_NOEXCEPT
Returns a reference to the last element.
Definition span.h:580
ETL_NODISCARD ETL_CONSTEXPR etl::span< element_type, etl::dynamic_extent > last(size_t count) const ETL_NOEXCEPT
Obtains a span that is a view over the last count elements of this span.
Definition span.h:772
ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crend() const ETL_NOEXCEPT
Returns a const reverse iterator to the end of the span.
Definition span.h:660
ETL_CONSTEXPR reference operator[](const size_t i) const
Returns a reference to the indexed value.
Definition span.h:738
ETL_NODISCARD ETL_CONSTEXPR const_iterator cend() const ETL_NOEXCEPT
Returns a const iterator to the end of the span.
Definition span.h:620
ETL_NODISCARD ETL_CONSTEXPR iterator begin() const ETL_NOEXCEPT
Returns an iterator to the beginning of the span.
Definition span.h:604
ETL_NODISCARD ETL_CONSTEXPR14 const_reference at(size_t i) const
Returns a const reference to the value at index 'i'.
Definition span.h:728
ETL_CONSTEXPR span(const TContainer &a, typename etl::enable_if<!etl::is_pointer< typename etl::remove_reference< TContainer >::type >::value &&!etl::is_array< TContainer >::value &&etl::is_same< typename etl::remove_cv< T >::type, typename etl::remove_cv< typename etl::remove_reference< TContainer >::type::value_type >::type >::value, void >::type *=0) ETL_NOEXCEPT
Definition span.h:541
ETL_NODISCARD ETL_CONSTEXPR reference front() const ETL_NOEXCEPT
Returns a reference to the first element.
Definition span.h:572
ETL_CONSTEXPR span(element_type(&begin_)[Array_Size]) ETL_NOEXCEPT
Construct from C array.
Definition span.h:503
ETL_NODISCARD ETL_CONSTEXPR iterator end() const ETL_NOEXCEPT
Returns an iterator to the end of the span.
Definition span.h:628
ETL_CONSTEXPR span(const TIterator begin_, const TIterator end_)
Construct from iterators.
Definition span.h:493
ETL_NODISCARD ETL_CONSTEXPR const_iterator cbegin() const ETL_NOEXCEPT
Returns a const iterator to the beginning of the span.
Definition span.h:596
ETL_NODISCARD ETL_CONSTEXPR pointer data() const ETL_NOEXCEPT
Returns a pointer to the first element of the internal storage.
Definition span.h:588
ETL_CONSTEXPR span(const TIterator begin_, const TSize size_) ETL_NOEXCEPT
Construct from pointer + size.
Definition span.h:483
ETL_NODISCARD ETL_CONSTEXPR reverse_iterator rend() const ETL_NOEXCEPT
Returns a reverse iterator to the end of the span.
Definition span.h:668
ETL_NODISCARD ETL_CONSTEXPR size_t max_size() const ETL_NOEXCEPT
Returns the maximum possible size of the span.
Definition span.h:700
ETL_NODISCARD ETL_CONSTEXPR size_t size_bytes() const ETL_NOEXCEPT
Returns the size of the span in bytes.
Definition span.h:692
ETL_NODISCARD ETL_CONSTEXPR14 reference at(size_t i)
Returns a reference to the value at index 'i'.
Definition span.h:718
Span - Fixed Extent.
Definition span.h:63
ETL_NODISCARD ETL_CONSTEXPR reverse_iterator rend() const ETL_NOEXCEPT
Returns a reverse iterator to the end of the span.
Definition span.h:265
ETL_NODISCARD ETL_CONSTEXPR circular_iterator begin_circular() const ETL_NOEXCEPT
Returns a circular iterator to the beginning of the span.
Definition span.h:209
ETL_NODISCARD ETL_CONSTEXPR const_iterator cbegin() const ETL_NOEXCEPT
Returns a const iterator to the beginning of the span.
Definition span.h:193
ETL_NODISCARD ETL_CONSTEXPR etl::span< element_type, COUNT > last() const ETL_NOEXCEPT
Obtains a span that is a view over the last COUNT elements of this span.
Definition span.h:363
ETL_CONSTEXPR span(const span &other) ETL_NOEXCEPT
Copy constructor.
Definition span.h:152
etl::span< element_type, COUNT !=etl::dynamic_extent ? COUNT :Extent - OFFSET > subspan() const
Obtains a span that is a view from OFFSET over the next COUNT elements of this span.
Definition span.h:401
ETL_NODISCARD ETL_CONSTEXPR etl::span< element_type, etl::dynamic_extent > first(size_t count) const ETL_NOEXCEPT
Obtains a span that is a view over the first count elements of this span.
Definition span.h:354
ETL_NODISCARD ETL_CONSTEXPR etl::span< element_type, etl::dynamic_extent > subspan(size_t offset, size_t count=etl::dynamic_extent) const ETL_NOEXCEPT
Obtains a span that is a view from 'offset' over the next 'count' elements of this span.
Definition span.h:423
ETL_NODISCARD ETL_CONSTEXPR etl::span< element_type, etl::dynamic_extent > last(size_t count) const ETL_NOEXCEPT
Obtains a span that is a view over the last count elements of this span.
Definition span.h:374
ETL_NODISCARD ETL_CONSTEXPR reverse_circular_iterator rbegin_circular() const ETL_NOEXCEPT
Returns a reverse circular iterator to the end of the span.
Definition span.h:249
ETL_NODISCARD ETL_CONSTEXPR iterator begin() const ETL_NOEXCEPT
Returns an iterator to the beginning of the span.
Definition span.h:201
ETL_CONSTEXPR span(const etl::span< U, N > &other, typename etl::enable_if<(Extent==etl::dynamic_extent)||(N==etl::dynamic_extent)||(N==Extent), void >::type) ETL_NOEXCEPT
Copy constructor.
Definition span.h:161
ETL_NODISCARD ETL_CONSTEXPR size_t size_bytes() const ETL_NOEXCEPT
Returns the size of the span in bytes.
Definition span.h:289
ETL_NODISCARD ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
Returns true if the span size is zero.
Definition span.h:273
ETL_NODISCARD ETL_CONSTEXPR const_iterator cend() const ETL_NOEXCEPT
Returns a const iterator to the end of the span.
Definition span.h:217
ETL_NODISCARD ETL_CONSTEXPR etl::span< element_type, COUNT > first() const ETL_NOEXCEPT
Obtains a span that is a view over the first COUNT elements of this span.
Definition span.h:343
ETL_NODISCARD ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
Returns the size of the span.
Definition span.h:281
ETL_NODISCARD ETL_CONSTEXPR reference back() const ETL_NOEXCEPT
Returns a reference to the last element.
Definition span.h:177
ETL_CONSTEXPR14 span & operator=(const span &other) ETL_NOEXCEPT
Assign from a span.
Definition span.h:305
ETL_CONSTEXPR span(const TIterator begin_, const TIterator)
Construct from iterators.
Definition span.h:97
ETL_CONSTEXPR span(element_type(&begin_)[Array_Size]) ETL_NOEXCEPT
Construct from C array.
Definition span.h:106
ETL_NODISCARD ETL_CONSTEXPR pointer data() const ETL_NOEXCEPT
Returns a pointer to the first element of the internal storage.
Definition span.h:185
ETL_CONSTEXPR span(const TContainer &a, typename etl::enable_if<!etl::is_pointer< typename etl::remove_reference< TContainer >::type >::value &&!etl::is_array< TContainer >::value &&etl::is_same< typename etl::remove_cv< T >::type, typename etl::remove_cv< typename etl::remove_reference< TContainer >::type::value_type >::type >::value, void >::type *=0) ETL_NOEXCEPT
Definition span.h:141
ETL_CONSTEXPR span(const TIterator begin_, const TSize) ETL_NOEXCEPT
Construct from iterators + size.
Definition span.h:88
ETL_NODISCARD ETL_CONSTEXPR14 reference at(size_t i)
Returns a reference to the value at index 'i'.
Definition span.h:314
ETL_CONSTEXPR reference operator[](const size_t i) const
Returns a reference to the indexed value.
Definition span.h:334
ETL_NODISCARD ETL_CONSTEXPR14 const_reference at(size_t i) const
Returns a const reference to the value at index 'i'.
Definition span.h:324
ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crend() const ETL_NOEXCEPT
Returns a const reverse iterator to the end of the span.
Definition span.h:257
span(TContainer &a, typename etl::enable_if<!etl::is_pointer< typename etl::remove_reference< TContainer >::type >::value &&!etl::is_array< TContainer >::value &&etl::is_same< typename etl::remove_cv< T >::type, typename etl::remove_cv< typename etl::remove_reference< TContainer >::type::value_type >::type >::value, void >::type *=0) ETL_NOEXCEPT
Definition span.h:129
ETL_NODISCARD ETL_CONSTEXPR size_t max_size() const ETL_NOEXCEPT
Returns the maximum possible size of the span.
Definition span.h:297
ETL_NODISCARD ETL_CONSTEXPR reference front() const ETL_NOEXCEPT
Returns a reference to the first element.
Definition span.h:169
ETL_NODISCARD ETL_CONSTEXPR iterator end() const ETL_NOEXCEPT
Returns an iterator to the end of the span.
Definition span.h:225
#define ETL_ASSERT(b, e)
Definition error_handler.h:356
enable_if
Definition type_traits_generator.h:1186
extent
Definition type_traits_generator.h:1197
is_array
Definition type_traits_generator.h:1086
is_const
Definition type_traits_generator.h:903
is_pointer
Definition type_traits_generator.h:1096
is_same
Definition type_traits_generator.h:1036
remove_cv
Definition type_traits_generator.h:963
remove_reference
Definition type_traits_generator.h:873
bitset_ext
Definition absolute.h:38
span< byte,(N==etl::dynamic_extent) ?(etl::dynamic_extent) :(N *sizeof(T))> as_writable_bytes(span< T, N > s) ETL_NOEXCEPT
Obtains a view to the byte representation of the elements of the span s.
Definition span.h:952
ETL_CONSTEXPR T * to_address(T *p)
Definition memory.h:62
span< const byte,(N==etl::dynamic_extent) ?(etl::dynamic_extent) :(N *sizeof(T))> as_bytes(span< T, N > s) ETL_NOEXCEPT
Template deduction guides.
Definition span.h:942
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:654
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:642
ETL_CONSTEXPR span< T, Extent > make_span(T(&data)[Extent])
Definition span.h:439
pair holds two objects of arbitrary type
Definition utility.h:164