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>
75 typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
85 template <
typename TIterator,
typename TSize>
94 template <
typename TIterator>
103 template<
size_t Array_Size>
114 template <
typename TContainer,
typename =
typename etl::enable_if<!etl::is_po
inter<etl::remove_reference_t<TContainer>>::value &&
115 !etl::is_array<etl::remove_reference_t<TContainer>>::value&&
116 etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<
typename etl::remove_reference_t<TContainer>::value_type>>::value,
void>::type>
126 template <
typename TContainer>
138 template <
typename TContainer>
151 : pbegin(
other.pbegin)
158 template <
typename U,
size_t N>
160 : pbegin(
other.data())
177 return *((pbegin +
Extent) - 1);
231 ETL_NODISCARD ETL_CONSTEXPR reverse_iterator
rend()
const ETL_NOEXCEPT
233 return reverse_iterator(pbegin);
247 ETL_NODISCARD ETL_CONSTEXPR
size_t size()
const ETL_NOEXCEPT
273 pbegin =
other.pbegin;
288 template <
size_t COUNT>
292 ETL_STATIC_ASSERT((
Extent != etl::dynamic_extent) ?
COUNT <=
Extent :
true,
"Original span does not contain COUNT elements");
308 template <
size_t COUNT>
312 ETL_STATIC_ASSERT((
Extent != etl::dynamic_extent) ?
COUNT <=
Extent :
true,
"Original span does not contain COUNT elements");
329 template <
size_t OFFSET,
size_t COUNT = etl::dynamic_extent>
330 ETL_NODISCARD ETL_CONSTEXPR
334 ETL_STATIC_ASSERT((
Extent != etl::dynamic_extent) ?
OFFSET <=
Extent :
true,
"OFFSET is not within the original span");
337 ETL_STATIC_ASSERT((
Extent != etl::dynamic_extent) && (
COUNT != etl::dynamic_extent) ?
COUNT <= (
Extent -
OFFSET) :
true,
"OFFSET + COUNT is not within the original span");
346 template <
size_t OFFSET,
size_t COUNT>
350 ETL_STATIC_ASSERT((
Extent != etl::dynamic_extent) ?
OFFSET <=
Extent :
true,
"OFFSET is not within the original span");
353 ETL_STATIC_ASSERT((
Extent != etl::dynamic_extent) && (
COUNT != etl::dynamic_extent) ?
COUNT <= (
Extent -
OFFSET) :
true,
"OFFSET + COUNT is not within the original span");
355 if (
COUNT == etl::dynamic_extent)
383 template <
typename T>
397 typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
402 static ETL_CONSTANT
size_t extent = etl::dynamic_extent;
407 ETL_CONSTEXPR
span() ETL_NOEXCEPT
408 : pbegin(ETL_NULLPTR)
416 template <
typename TIterator,
typename TSize>
426 template <
typename TIterator>
436 template<
size_t Array_Size>
439 , pend(
begin_ + Array_Size)
448 template <
typename TContainer,
typename =
typename etl::enable_if<!etl::is_po
inter<etl::remove_reference_t<TContainer>>::value &&
449 !etl::is_array<etl::remove_reference_t<TContainer>>::value &&
450 etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<
typename etl::remove_reference_t<TContainer>::value_type>>::value,
void>::type>
453 , pend(a.data() + a.size())
461 template <
typename TContainer>
474 template <
typename TContainer>
488 : pbegin(
other.pbegin)
496 template <
typename U,
size_t N>
498 : pbegin(
other.data())
570 ETL_NODISCARD ETL_CONSTEXPR reverse_iterator
rend()
const ETL_NOEXCEPT
572 return reverse_iterator(pbegin);
580 return (pbegin == pend);
586 ETL_NODISCARD ETL_CONSTEXPR
size_t size()
const ETL_NOEXCEPT
588 return (pend - pbegin);
612 pbegin =
other.pbegin;
628 template <
size_t COUNT>
645 template <
size_t COUNT>
663 template <
size_t OFFSET,
size_t COUNT = etl::dynamic_extent>
664 ETL_NODISCARD ETL_CONSTEXPR
674 template <
size_t OFFSET,
size_t COUNT>
677 if (
COUNT == etl::dynamic_extent)
703 template <
typename T,
size_t Extent>
704 ETL_CONSTANT
size_t span<T, Extent>::extent;
706 template <
typename T>
707 ETL_CONSTANT
size_t span<T, etl::dynamic_extent>::extent;
712 template <
typename T1,
size_t N1,
typename T2,
size_t N2>
718 return (
lhs.begin() ==
rhs.begin()) && (
lhs.size() ==
rhs.size());
724 template <
typename T1,
size_t N1,
typename T2,
size_t N2>
740 template <
typename T1,
size_t N1,
typename T2,
size_t N2>
744 return (
lhs.empty() &&
rhs.empty()) ||
745 ((
lhs.begin() ==
rhs.begin()) && (
lhs.size() ==
rhs.size())) ||
746 etl::equal(
lhs.begin(),
lhs.end(),
rhs.begin(),
rhs.end());
753 template <
typename TIterator>
754 span(
const TIterator begin_,
const TIterator end_)
757 template <
typename TIterator,
typename TSize>
758 span(
const TIterator begin_,
const TSize size_)
761 template <
typename T,
size_t N>
765 template <
typename T,
size_t N>
769 template <
typename T,
size_t N>
773#if ETL_USING_STL && ETL_USING_CPP11
774 template <
typename T,
size_t N>
775 span(std::array<T, N>&)
778 template <
typename T,
size_t N>
779 span(
const std::array<T, N>&)
787#if ETL_USING_8BIT_TYPES
788 template <
typename T,
size_t Extent>
789 struct hash<
etl::span<T, Extent> >
793 return etl::private_hash::generic_hash<size_t>(
reinterpret_cast<const uint8_t*
>(view.data()),
794 reinterpret_cast<const uint8_t*
>(view.data() + view.size()));
802 template <
class T,
size_t N>
803 span<
const byte, (N == etl::dynamic_extent) ? (etl::dynamic_extent) : (N *
sizeof(T))>
812 template <
class T,
size_t N>
813 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:538
ETL_CONSTEXPR span(const span &other) ETL_NOEXCEPT
Copy constructor.
Definition span.h:487
ETL_CONSTEXPR span() ETL_NOEXCEPT
Default constructor.
Definition span.h:407
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:675
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:562
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:629
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:462
ETL_NODISCARD ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
Returns the size of the span.
Definition span.h:586
ETL_CONSTEXPR span(const etl::span< U, N > &other) ETL_NOEXCEPT
Copy constructor.
Definition span.h:497
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:691
ETL_NODISCARD ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
Returns true if the span size is zero.
Definition span.h:578
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:646
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:637
ETL_NODISCARD ETL_CONSTEXPR reference back() const ETL_NOEXCEPT
Returns a reference to the last element.
Definition span.h:514
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:654
ETL_CONSTEXPR reference operator[](const size_t i) const
Returns a reference to the indexed value.
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:530
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:475
ETL_NODISCARD ETL_CONSTEXPR reference front() const ETL_NOEXCEPT
Returns a reference to the first element.
Definition span.h:506
ETL_CONSTEXPR span(element_type(&begin_)[Array_Size]) ETL_NOEXCEPT
Construct from C array.
Definition span.h:437
ETL_NODISCARD ETL_CONSTEXPR iterator end() const ETL_NOEXCEPT
Returns an iterator to the end of the span.
Definition span.h:546
ETL_CONSTEXPR span(const TIterator begin_, const TIterator end_)
Construct from iterators.
Definition span.h:427
ETL_NODISCARD ETL_CONSTEXPR pointer data() const ETL_NOEXCEPT
Returns a pointer to the first element of the internal storage.
Definition span.h:522
ETL_CONSTEXPR span(const TIterator begin_, const TSize size_) ETL_NOEXCEPT
Construct from pointer + size.
Definition span.h:417
ETL_NODISCARD ETL_CONSTEXPR reverse_iterator rend() const ETL_NOEXCEPT
Returns a reverse iterator to the end of the span.
Definition span.h:570
ETL_NODISCARD ETL_CONSTEXPR size_t max_size() const ETL_NOEXCEPT
Returns the maximum possible size of the span.
Definition span.h:602
ETL_NODISCARD ETL_CONSTEXPR size_t size_bytes() const ETL_NOEXCEPT
Returns the size of the span in bytes.
Definition span.h:594
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:231
ETL_NODISCARD ETL_CONSTEXPR circular_iterator begin_circular() const ETL_NOEXCEPT
Returns a circular iterator to the beginning of the span.
Definition span.h:199
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:309
ETL_CONSTEXPR span(const span &other) ETL_NOEXCEPT
Copy constructor.
Definition span.h:150
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:347
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:300
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:369
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:320
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:223
ETL_NODISCARD ETL_CONSTEXPR iterator begin() const ETL_NOEXCEPT
Returns an iterator to the beginning of the span.
Definition span.h:191
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:159
ETL_NODISCARD ETL_CONSTEXPR size_t size_bytes() const ETL_NOEXCEPT
Returns the size of the span in bytes.
Definition span.h:255
ETL_NODISCARD ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
Returns true if the span size is zero.
Definition span.h:239
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:289
ETL_NODISCARD ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
Returns the size of the span.
Definition span.h:247
ETL_NODISCARD ETL_CONSTEXPR reference back() const ETL_NOEXCEPT
Returns a reference to the last element.
Definition span.h:175
ETL_CONSTEXPR14 span & operator=(const span &other) ETL_NOEXCEPT
Assign from a span.
Definition span.h:271
ETL_CONSTEXPR span(const TIterator begin_, const TIterator)
Construct from iterators.
Definition span.h:95
ETL_CONSTEXPR span(element_type(&begin_)[Array_Size]) ETL_NOEXCEPT
Construct from C array.
Definition span.h:104
ETL_NODISCARD ETL_CONSTEXPR pointer data() const ETL_NOEXCEPT
Returns a pointer to the first element of the internal storage.
Definition span.h:183
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:139
ETL_CONSTEXPR span(const TIterator begin_, const TSize) ETL_NOEXCEPT
Construct from iterators + size.
Definition span.h:86
ETL_CONSTEXPR reference operator[](const size_t i) const
Returns a reference to the indexed value.
Definition span.h:280
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:127
ETL_NODISCARD ETL_CONSTEXPR size_t max_size() const ETL_NOEXCEPT
Returns the maximum possible size of the span.
Definition span.h:263
ETL_NODISCARD ETL_CONSTEXPR reference front() const ETL_NOEXCEPT
Returns a reference to the first element.
Definition span.h:167
ETL_NODISCARD ETL_CONSTEXPR iterator end() const ETL_NOEXCEPT
Returns an iterator to the end of the span.
Definition span.h:207
ETL_CONSTEXPR17 etl::enable_if<!etl::is_same< T, etl::nullptr_t >::value, T >::type * addressof(T &t)
Definition addressof.h:52
enable_if
Definition type_traits_generator.h:1191
extent
Definition type_traits_generator.h:1202
is_array
Definition type_traits_generator.h:1091
is_const
Definition type_traits_generator.h:908
is_pointer
Definition type_traits_generator.h:1101
is_same
Definition type_traits_generator.h:1041
remove_cv
Definition type_traits_generator.h:968
remove_reference
Definition type_traits_generator.h:878
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:814
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:804
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
pair holds two objects of arbitrary type
Definition utility.h:164