Difference between revisions of "cpp/container/span"
m (Added Spanish language link) |
(→Member functions: ~) |
||
Line 51: | Line 51: | ||
{{dsc h2 | Iterators}} | {{dsc h2 | Iterators}} | ||
− | {{dsc inc | cpp/container | + | {{dsc inc | cpp/container/dsc begin | span}} |
− | {{dsc inc | cpp/container | + | {{dsc inc | cpp/container/dsc end | span}} |
− | {{dsc inc | cpp/container | + | {{dsc inc | cpp/container/dsc rbegin | span}} |
− | {{dsc inc | cpp/container | + | {{dsc inc | cpp/container/dsc rend | span}} |
{{dsc h2 | Element access}} | {{dsc h2 | Element access}} |
Revision as of 17:54, 29 May 2020
Defined in header <span>
|
||
template< class T, |
(since C++20) | |
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.
A typical implementation holds only two members: a pointer to T
and a size.
Contents |
Template parameters
T | - | element type; must be a complete type that is not an abstract class type |
Extent | - | the number of elements in the sequence, or std::dynamic_extent if dynamic
|
Member types
Member type | Definition |
element_type
|
T
|
value_type
|
std::remove_cv_t<T> |
size_type
|
std::size_t |
difference_type
|
std::ptrdiff_t |
pointer
|
T*
|
const_pointer
|
const T*
|
reference
|
T&
|
const_reference
|
const T&
|
iterator
|
implementation-defined LegacyRandomAccessIterator, ConstexprIterator, and LegacyContiguousIterator whose value_type is value_type
|
reverse_iterator
|
std::reverse_iterator<iterator> |
Note: iterator
is a mutable iterator if T
is not const-qualified.
All requirements on the iterator types of a Container apply to the iterator
type of span
as well.
Member constant
static constexpr std::size_t extent = Extent; |
||
Member functions
constructs a span (public member function) | |
assigns a span (public member function) | |
Iterators | |
(C++23) |
returns an iterator to the beginning (public member function) |
(C++23) |
returns an iterator to the end (public member function) |
(C++23) |
returns a reverse iterator to the beginning (public member function) |
(C++23) |
returns a reverse iterator to the end (public member function) |
Element access | |
access the first element (public member function) | |
access the last element (public member function) | |
Observers | |
(C++20) |
returns the number of elements in the sequence (public member function) |
returns the size of the sequence in bytes (public member function) | |
checks if the sequence is empty (public member function) | |
Subviews | |
obtains a subspan consisting of the first N elements of the sequence (public member function) | |
obtains a subspan consisting of the last N elements of the sequence (public member function) | |
obtains a subspan (public member function) |
Non-member functions
(C++20) |
converts a span into a view of its underlying bytes (function template) |
Non-member constant
(C++20) |
a constant of type std::size_t signifying that the span has dynamic extent (constant) |
Helper template
template<class T, std::size_t Extent> inline constexpr bool ranges::enable_borrowed_range<std::span<T, Extent>> = true; |
||
This specialization of std::ranges::enable_borrowed_range makes span
satisfy borrowed_range
.
template<class T, std::size_t Extent> inline constexpr bool ranges::enable_view<std::span<T, Extent>> = |
||
This specialization of std::ranges::enable_view makes span
of zero or dynamic extent satisfy view
. Spans of nonzero static extent are not default_initializable
and therefore not views.