3#ifndef TETL_SPAN_SPAN_HPP
4#define TETL_SPAN_SPAN_HPP
54template <
typename T,
size_t Extent = etl::dynamic_extent>
60inline constexpr auto is_span =
false;
62template <
typename T,
size_t Size>
63inline constexpr auto is_span<etl::span<T, Size>> =
true;
65template <
typename From,
typename To>
68template <
size_t Offset,
size_t Count,
size_t Extent>
69[[nodiscard]]
consteval auto subspan_extent() ->
size_t
75 return Extent - Offset;
82template <
typename T,
size_t Extent>
110 template <typename It>
121 : _storage{&arr[0], N}
126 template <detail::span_convertible_from<T> U,
size_t N>
129 : _storage{arr.data(), arr.size()}
134 template <detail::span_convertible_from<T> U,
size_t N>
137 : _storage{arr.data(), arr.size()}
142 template <
typename R>
145 ranges::sized_range<R>
149 and not detail::is_span<R>
150 and detail::span_convertible_from<remove_reference_t<ranges::range_reference_t<R>>, T>
154 : _storage{r.
data(), ranges::
size(r)}
158 template <detail::span_convertible_from<T> U,
size_t N>
161 : _storage{source.data(), source.size()}
166 constexpr span(
span const& other)
noexcept =
default;
170 [[nodiscard]]
constexpr auto begin() const noexcept ->
iterator {
return _storage.data(); }
214 [[nodiscard]]
constexpr auto data() const noexcept ->
pointer {
return _storage.data(); }
217 [[nodiscard]]
constexpr auto size() const noexcept ->
size_type {
return _storage.size(); }
223 [[nodiscard]]
constexpr auto empty() const noexcept ->
bool {
return size() == 0; }
227 template <
size_t Count>
230 static_assert(Count <= Extent);
244 template <
size_t Count>
247 static_assert(Count <= Extent);
263 template <
size_t Offset,
size_t Count = dynamic_extent>
264 [[nodiscard]]
constexpr auto subspan() const ->
span<T, detail::subspan_extent<Offset, Count, Extent>()>
266 static_assert(Offset <= Extent);
267 static_assert(Count ==
dynamic_extent or Count <= Extent - Offset);
269 auto const ptr =
data() + Offset;
288 struct static_storage {
289 constexpr static_storage() =
default;
290 constexpr static_storage(T* ptr,
size_type ) noexcept
295 [[nodiscard]]
constexpr auto data() const noexcept {
return _data; }
296 [[nodiscard]]
constexpr auto size() const noexcept {
return Extent; }
302 struct dynamic_storage {
303 constexpr dynamic_storage() =
default;
304 constexpr dynamic_storage(T* ptr,
size_type sz) noexcept
310 [[nodiscard]]
constexpr auto data() const noexcept {
return _data; }
311 [[nodiscard]]
constexpr auto size() const noexcept {
return _size; }
323template <
typename Type,
size_t Extent>
327template <
typename Type,
size_t Size>
331template <
typename Type,
size_t Size>
339template <
typename T, etl::
size_t Extent>
344template <
typename T, etl::
size_t N>
355template <
typename T,
size_t N>
358 return {
reinterpret_cast<byte const*
>(s.data()), s.size_bytes()};
369template <
typename T,
size_t N>
#define TETL_PRECONDITION(...)
Definition check.hpp:16
ValueType[Size] c_array
Definition c_array.hpp:12
constexpr bool enable_borrowed_range
Definition enable_borrowed_range.hpp:10
constexpr auto dynamic_extent
etl::dynamic_extent is a constant of type etl::size_t that is used to differentiate etl::span of stat...
Definition dynamic_extent.hpp:14
auto as_bytes(span< T, N > s) noexcept -> span< byte const, detail::span_as_bytes_size< T, N > >
Obtains a view to the object representation of the elements of the span s.
Definition span.hpp:356
auto as_writable_bytes(span< T, N > s) noexcept -> span< byte, detail::span_as_bytes_size< T, N > >
Obtains a view to the object representation of the elements of the span s.
Definition span.hpp:371
typename remove_reference< T >::type remove_reference_t
Definition remove_reference.hpp:28
typename type_identity< T >::type type_identity_t
Definition type_identity.hpp:16
Definition ranges_in_fun_result.hpp:11
Definition adjacent_find.hpp:8
typename conditional< B, T, F >::type conditional_t
Definition conditional.hpp:21
constexpr bool is_const_v
Definition is_const.hpp:20
remove_const_t< remove_volatile_t< T > > remove_cv_t
Definition remove_cv.hpp:22
constexpr bool is_array_v
Definition is_array.hpp:26
constexpr auto is_etl_array
Definition array.hpp:331
TETL_BUILTIN_PTRDIFF ptrdiff_t
etl::ptrdiff_t is the signed integer type of the result of subtracting two pointers.
Definition ptrdiff_t.hpp:14
span(c_array< Type, Extent > &) -> span< Type, Extent >
decltype(*etl::declval< T & >()) iter_reference_t
Definition iter_reference_t.hpp:12
constexpr bool is_convertible_v
Definition is_convertible.hpp:46
TETL_BUILTIN_SIZET size_t
etl::size_t is the unsigned integer type of the result of the sizeof operator.
Definition size_t.hpp:14
A container that encapsulates fixed size arrays.
Definition array.hpp:48
array(T, U...) -> array< T, 1+sizeof...(U)>
One deduction guide is provided for array to provide an equivalent of experimental::make_array for co...
reverse_iterator is an iterator adaptor that reverses the direction of a given iterator....
Definition reverse_iterator.hpp:22
A non-owning view over a contiguous sequence of objects.
Definition span.hpp:83
static constexpr size_type extent
The number of elements in the sequence, or etl::dynamic_extent if dynamic.
Definition span.hpp:97
T & reference
Definition span.hpp:90
constexpr auto subspan(size_type offset, size_type count=dynamic_extent) const -> span< T, dynamic_extent >
Obtains a span that is a view over the Count elements of this span starting at offset Offset....
Definition span.hpp:278
constexpr auto rbegin() const noexcept -> reverse_iterator
Returns a reverse iterator to the first element of the reversed span. It corresponds to the last elem...
Definition span.hpp:180
constexpr auto last() const -> span< element_type, Count >
Obtains a span that is a view over the last Count elements of this span. The program is ill-formed if...
Definition span.hpp:245
etl::ptrdiff_t difference_type
Definition span.hpp:87
explicit(extent !=dynamic_extent) const expr span(It first
Constructs a span.
etl::size_t size_type
Definition span.hpp:86
constexpr auto size_bytes() const noexcept -> size_type
Returns the number of elements in the span.
Definition span.hpp:220
T * iterator
Definition span.hpp:92
constexpr auto rend() const noexcept -> reverse_iterator
Returns a reverse iterator to the element following the last element of the reversed span....
Definition span.hpp:186
size_type count
Definition span.hpp:113
constexpr auto subspan() const -> span< T, detail::subspan_extent< Offset, Count, Extent >()>
Obtains a span that is a view over the Count elements of this span starting at offset Offset....
Definition span.hpp:264
constexpr auto end() const noexcept -> iterator
Returns an iterator to the element following the last element of the span. This element acts as a pla...
Definition span.hpp:175
constexpr auto operator[](size_type idx) const -> reference
Returns a reference to the idx-th element of the sequence. The behavior is undefined if idx is out of...
Definition span.hpp:207
constexpr auto first() const -> span< element_type, Count >
Obtains a span that is a view over the first Count elements of this span. The program is ill-formed i...
Definition span.hpp:228
constexpr auto data() const noexcept -> pointer
Returns a pointer to the beginning of the sequence.
Definition span.hpp:214
constexpr auto begin() const noexcept -> iterator
Returns an iterator to the first element of the span. If the span is empty, the returned iterator wil...
Definition span.hpp:170
constexpr auto empty() const noexcept -> bool
Checks if the span is empty.
Definition span.hpp:223
etl::reverse_iterator< iterator > reverse_iterator
Definition span.hpp:93
constexpr auto last(size_type count) const -> span< element_type, dynamic_extent >
Obtains a span that is a view over the last Count elements of this span. The behavior is undefined if...
Definition span.hpp:253
T * pointer
Definition span.hpp:88
T element_type
Definition span.hpp:84
constexpr auto back() const -> reference
Returns a reference to the last element in the span. Calling front on an empty span results in undefi...
Definition span.hpp:198
constexpr auto first(size_type count) const -> span< element_type, dynamic_extent >
Obtains a span that is a view over the first Count elements of this span. The behavior is undefined i...
Definition span.hpp:236
T const * const_pointer
Definition span.hpp:89
etl::remove_cv_t< T > value_type
Definition span.hpp:85
constexpr auto front() const -> reference
Returns a reference to the first element in the span. Calling front on an empty span results in undef...
Definition span.hpp:190
constexpr auto size() const noexcept -> size_type
Returns the number of elements in the span.
Definition span.hpp:217
T const & const_reference
Definition span.hpp:91
constexpr span() noexcept=default
Constructs a span. Constructs an empty span whose data() == nullptr and size() == 0.