Note, this article is not finished! You can help by editing this doc page.
Span class reference
Overview
- Simplified
- Detailed
template< class T, /* ... */ >
class span;
template<
class T,
std::size_t Extent = std::dynamic_extent
> class span;
std::span
is a view over a dynamic or static contiguous container.
Memory
This section requires improvement. You can help by editing this doc page.
Technical details
Technical details
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 at compile-time and encoded in the type
- a typical implementation may have only one member - a pointer to
T
-
dynamic extent, in which case:
- the number of elements is not known at compile-time and can change at runtime
- a typical implementation holds two members - a pointer to
T
and a size
Named requirements
std::span
meets the requirements of:
-
TriviallyCopyable (since C++23)
-
note
Specializations of
std::span
are already trivially copyable types in all existing implementations, even before the formal requirement introduced in C++23.
-
Feature testing macros
This section requires improvement. You can help by editing this doc page.
std::span
Defined in | span |
Template parameters
pub | T | Type of the elements. |
pub | Extent | Number of elements in the container or |
Type names
pub | element_type | T |
pub | value_type | std::remove_cv_t<T> |
pub | size_type | Unsigned integer type (usually std::size_t ) |
pub | difference_type | Signed integer type (usually std::ptrdiff_t ) |
pub | pointer | T* |
pub | const_pointer | const T* |
pub | reference | T& |
pub | const_reference | T const& |
pub | iterator | Implementation-defined |
pub | reverse_iterator | std::reverse_iterator<iterator> |
Member functions
pub | (constructors) | Constructs a span. |
pub | (destructor) | Destroys the span. |
pub | operator= | Assigns values to the container. |
Element access
pub | front | Returns the first element. |
pub | back | Returns the last element. |
pub | operator[] | Accesses a specified element. |
pub | data | Returns a pointer to the first element of the underlying array. |
Iterators
pub | begin | Returns an |
pub | end | Returns an |
pub | rbegin | Returns a reverse |
pub | rend | Returns a reverse |