tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
span< T, Extent > Struct Template Reference

A non-owning view over a contiguous sequence of objects. More...

#include <span.hpp>

Public Types

using const_pointer = T const*
 
using const_reference = T const&
 
using difference_type = etl::ptrdiff_t
 
using element_type = T
 
using iterator = T*
 
using pointer = T*
 
using reference = T&
 
using reverse_iterator = etl::reverse_iterator<iterator>
 
using size_type = etl::size_t
 
using value_type = etl::remove_cv_t<T>
 

Public Member Functions

constexpr span () noexcept=default
 Constructs a span. Constructs an empty span whose data() == nullptr and size() == 0.
 
constexpr auto back () const -> reference
 Returns a reference to the last element in the span. Calling front on an empty span results in undefined behavior.
 
constexpr auto begin () const noexcept -> iterator
 Returns an iterator to the first element of the span. If the span is empty, the returned iterator will be equal to end().
 
constexpr auto data () const noexcept -> pointer
 Returns a pointer to the beginning of the sequence.
 
constexpr auto empty () const noexcept -> bool
 Checks if the span is empty.
 
constexpr auto end () const noexcept -> iterator
 Returns an iterator to the element following the last element of the span. This element acts as a placeholder; attempting to access it results in undefined behavior.
 
template<typename It>
requires detail::span_convertible_from<remove_reference_t<iter_reference_t<It>>, T>
 explicit (extent !=dynamic_extent) const expr span(It first
 Constructs a span.
 
template<size_t Count>
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 if Count > Extent.
 
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 if Count > size().
 
constexpr auto front () const -> reference
 Returns a reference to the first element in the span. Calling front on an empty span results in undefined behavior.
 
template<size_t Count>
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 Count > Extent.
 
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 Count > size().
 
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 range (i.e., if it is greater than or equal to size()).
 
constexpr auto rbegin () const noexcept -> reverse_iterator
 Returns a reverse iterator to the first element of the reversed span. It corresponds to the last element of the non-reversed span. If the span is empty, the returned iterator is equal to rend().
 
constexpr auto rend () const noexcept -> reverse_iterator
 Returns a reverse iterator to the element following the last element of the reversed span. It corresponds to the element preceding the first element of the non-reversed span. This element acts as a placeholder, attempting to access it results in undefined behavior.
 
constexpr auto size () const noexcept -> size_type
 Returns the number of elements in the span.
 
constexpr auto size_bytes () const noexcept -> size_type
 Returns the number of elements in the span.
 
template<size_t Offset, size_t Count = dynamic_extent>
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. If Count is etl::dynamic_extent, the number of elements in the subspan is size() - offset (i.e., it ends at the end of *this.).
 
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. If Count is etl::dynamic_extent, the number of elements in the subspan is size() - offset (i.e., it ends at the end of *this.).
 

Public Attributes

size_type count: _storage{first
 

Static Public Attributes

static constexpr size_type extent = Extent
 The number of elements in the sequence, or etl::dynamic_extent if dynamic.
 

Related Symbols

(Note that these are not member symbols.)

template<typename T, size_t N>
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.
 
template<typename T, size_t N>
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.
 

Detailed Description

template<typename T, size_t Extent>
struct etl::span< T, Extent >

A non-owning view over a contiguous sequence of objects.

The class template span describes an object that can refer to a contiguous sequence of objects with the first element of the sequence at position zero. A span can either have a static extent, in which case the number of elements in the sequence is known and encoded in the type, or a dynamic extent.

If a span has dynamic extent a typical implementation holds two members: a pointer to T and a size. A span with static extent may have only one member: a pointer to T.

Examples
numeric.cpp.

Member Typedef Documentation

◆ const_pointer

template<typename T, size_t Extent>
using const_pointer = T const*

◆ const_reference

template<typename T, size_t Extent>
using const_reference = T const&

◆ difference_type

template<typename T, size_t Extent>
using difference_type = etl::ptrdiff_t

◆ element_type

template<typename T, size_t Extent>
using element_type = T

◆ iterator

template<typename T, size_t Extent>
using iterator = T*

◆ pointer

template<typename T, size_t Extent>
using pointer = T*

◆ reference

template<typename T, size_t Extent>
using reference = T&

◆ reverse_iterator

template<typename T, size_t Extent>
using reverse_iterator = etl::reverse_iterator<iterator>

◆ size_type

template<typename T, size_t Extent>
using size_type = etl::size_t

◆ value_type

template<typename T, size_t Extent>
using value_type = etl::remove_cv_t<T>

Constructor & Destructor Documentation

◆ span()

template<typename T, size_t Extent>
span ( )
constexprdefaultnoexcept

Constructs a span. Constructs an empty span whose data() == nullptr and size() == 0.

This overload only participates in overload resolution if extent == 0 || extent == etl::dynamic_extent.

Member Function Documentation

◆ back()

template<typename T, size_t Extent>
auto back ( ) const -> reference
inlinenodiscardconstexpr

Returns a reference to the last element in the span. Calling front on an empty span results in undefined behavior.

◆ begin()

template<typename T, size_t Extent>
auto begin ( ) const -> iterator
inlinenodiscardconstexprnoexcept

Returns an iterator to the first element of the span. If the span is empty, the returned iterator will be equal to end().

◆ data()

template<typename T, size_t Extent>
auto data ( ) const -> pointer
inlinenodiscardconstexprnoexcept

Returns a pointer to the beginning of the sequence.

◆ empty()

template<typename T, size_t Extent>
auto empty ( ) const -> bool
inlinenodiscardconstexprnoexcept

Checks if the span is empty.

◆ end()

template<typename T, size_t Extent>
auto end ( ) const -> iterator
inlinenodiscardconstexprnoexcept

Returns an iterator to the element following the last element of the span. This element acts as a placeholder; attempting to access it results in undefined behavior.

◆ explicit()

template<typename T, size_t Extent>
template<typename It>
requires detail::span_convertible_from<remove_reference_t<iter_reference_t<It>>, T>
explicit ( extent ! = dynamic_extent) const

Constructs a span.

Constructs a span that is a view over the range [first, first + count);

◆ first() [1/2]

template<typename T, size_t Extent>
template<size_t Count>
auto first ( ) const -> span<element_type, Count>
inlinenodiscardconstexpr

Obtains a span that is a view over the first Count elements of this span. The program is ill-formed if Count > Extent.

◆ first() [2/2]

template<typename T, size_t Extent>
auto first ( size_type count) const -> span<element_type, dynamic_extent>
inlinenodiscardconstexpr

Obtains a span that is a view over the first Count elements of this span. The behavior is undefined if Count > size().

◆ front()

template<typename T, size_t Extent>
auto front ( ) const -> reference
inlinenodiscardconstexpr

Returns a reference to the first element in the span. Calling front on an empty span results in undefined behavior.

◆ last() [1/2]

template<typename T, size_t Extent>
template<size_t Count>
auto last ( ) const -> span<element_type, Count>
inlinenodiscardconstexpr

Obtains a span that is a view over the last Count elements of this span. The program is ill-formed if Count > Extent.

◆ last() [2/2]

template<typename T, size_t Extent>
auto last ( size_type count) const -> span<element_type, dynamic_extent>
inlinenodiscardconstexpr

Obtains a span that is a view over the last Count elements of this span. The behavior is undefined if Count > size().

◆ operator[]()

template<typename T, size_t Extent>
auto operator[] ( size_type idx) const -> reference
inlinenodiscardconstexpr

Returns a reference to the idx-th element of the sequence. The behavior is undefined if idx is out of range (i.e., if it is greater than or equal to size()).

◆ rbegin()

template<typename T, size_t Extent>
auto rbegin ( ) const -> reverse_iterator
inlinenodiscardconstexprnoexcept

Returns a reverse iterator to the first element of the reversed span. It corresponds to the last element of the non-reversed span. If the span is empty, the returned iterator is equal to rend().

◆ rend()

template<typename T, size_t Extent>
auto rend ( ) const -> reverse_iterator
inlinenodiscardconstexprnoexcept

Returns a reverse iterator to the element following the last element of the reversed span. It corresponds to the element preceding the first element of the non-reversed span. This element acts as a placeholder, attempting to access it results in undefined behavior.

◆ size()

template<typename T, size_t Extent>
auto size ( ) const -> size_type
inlinenodiscardconstexprnoexcept

Returns the number of elements in the span.

◆ size_bytes()

template<typename T, size_t Extent>
auto size_bytes ( ) const -> size_type
inlinenodiscardconstexprnoexcept

Returns the number of elements in the span.

◆ subspan() [1/2]

template<typename T, size_t Extent>
template<size_t Offset, size_t Count = dynamic_extent>
auto subspan ( ) const -> span<T, detail::subspan_extent<Offset, Count, Extent>()>
inlinenodiscardconstexpr

Obtains a span that is a view over the Count elements of this span starting at offset Offset. If Count is etl::dynamic_extent, the number of elements in the subspan is size() - offset (i.e., it ends at the end of *this.).

◆ subspan() [2/2]

template<typename T, size_t Extent>
auto subspan ( size_type offset,
size_type count = dynamic_extent ) const -> span<T, dynamic_extent>
inlinenodiscardconstexpr

Obtains a span that is a view over the Count elements of this span starting at offset Offset. If Count is etl::dynamic_extent, the number of elements in the subspan is size() - offset (i.e., it ends at the end of *this.).

Member Data Documentation

◆ count

template<typename T, size_t Extent>
size_type count

◆ extent

template<typename T, size_t Extent>
size_type extent = Extent
staticconstexpr

The number of elements in the sequence, or etl::dynamic_extent if dynamic.


The documentation for this struct was generated from the following file: