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
Named requirements
Feature testing macros
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 |
Observers
pub | size | Returns the number of elements. |
pub | size_bytes | Returns the maximum possible number of elements. |
pub | empty | Returns |
Subviews
pub | first | Clears the contents. |
pub | last | Inserts elements. |
pub | subspan | Removes elements. |
Constants
static constexpr std::size_t extent = Extent;
Non-member functions
pub | as_bytes as_writable_bytes | Lexicographically compares the values in the span. |
Non-member constants
pub | std::dynamic_extent | A constant of type |
Helper templates
- since C++20
template<class T, std::size_t Extent>
inline constexpr bool ranges::enable_borrowed_range<std::span<T, Extent>> = true;
This specialization of ranges::enable_borrowed_range
makes span
satisfy borrowed_range
.
- since C++20
template<class T, std::size_t Extent>
inline constexpr bool ranges::enable_view<std::span<T, Extent>> = true;
This specialization of ranges::enable_view
makes span
satisfy view
.
Deduction guides (since C++17)
Click to expand
Examples
This section requires improvement. You can help by editing this doc page.
Hover to see the original license.