constexpr span() noexcept; | (1) | (since C++20) |
template< class It > explicit(extent != std::dynamic_extent) constexpr span( It first, size_type count ); | (2) | (since C++20) |
template< class It, class End > explicit(extent != std::dynamic_extent) constexpr span( It first, End last ); | (3) | (since C++20) |
template< std::size_t N > constexpr span( std::type_identity_t<element_type> (&arr)[N] ) noexcept; | (4) | (since C++20) |
template< class U, std::size_t N > constexpr span( std::array<U, N>& arr ) noexcept; | (5) | (since C++20) |
template< class U, std::size_t N > constexpr span( const std::array<U, N>& arr ) noexcept; | (6) | (since C++20) |
template< class R > explicit(extent != std::dynamic_extent) constexpr span( R&& range ); | (7) | (since C++20) |
template< class U, std::size_t N > explicit(extent != std::dynamic_extent && N == std::dynamic_extent) constexpr span( const std::span<U, N>& source ) noexcept; | (8) | (since C++20) |
constexpr span( const span& other ) noexcept = default; | (9) | (since C++20) |
Constructs a span.
data() == nullptr and size() == 0. extent == 0 || extent == std::dynamic_extent.[first, first + count); the resulting span has data() == std::to_address(first) and size() == count. [first, first + count) is not a valid range, if It does not actually model contiguous_iterator, or if extent != std::dynamic_extent && count != extent. It satisfies contiguous_iterator std::iter_reference_t<It> to element_type is at most a qualification conversion.[first, last); the resulting span has data() == std::to_address(first) and size() == last-first. [first, last) is not a valid range, if It does not actually model contiguous_iterator, if End does not actually model sized_sentinel_for for It, or if extent != std::dynamic_extent && last-first != extent. It satisfies contiguous_iterator, End satisfies sized_sentinel_for for It, std::iter_reference_t<It> to element_type is at most a qualification conversion, and std::is_convertible_v<End, std::size_t> is false.arr; the resulting span has size() == N and data() == std::data(arr). extent == std::dynamic_extent || N == extent is true and the conversion from std::remove_pointer_t<decltype(data(arr))> to element_type is at most a qualification conversion.range; the resulting span has size() == std::ranges::size(range) and data() == std::ranges::data(range). R does not actually model contiguous_range and sized_range or if R does not model borrowed_range while element_type is non-const or both extent != dynamic_extent and std::ranges::size(range) != extent are true. R satisfies contiguous_range and sized_range, R satisfies borrowed_range or std::is_const_v<element_type> is true std::remove_cvref_t<R> is not a specialization of std::span, std::remove_cvref_t<R> is not a specialization of std::array std::is_array_v<std::remove_cvref_t<R>> is false, and std::ranges::range_reference_t<R> to element_type is at most a qualification conversion.source; the resulting span has size() == source.size() and data() == source.data(). extent != dynamic_extent and source.size() != extent are true. extent == std::dynamic_extent, N == std::dynamic_extent and N == extent is true and the conversion from U to element_type is at most a qualification conversion.size() == other.size() and data() == other.data().| first | - | iterator to the first element of the sequence |
| count | - | number of elements in the sequence |
| last | - | iterator past the last element of the sequence or another sentinel |
| arr | - | array to construct a view for |
| range | - | range to construct a view for |
| source | - | another span to convert from |
| other | - | another span to copy from |
last - first throws.|
(C++20) | returns a pointer to the beginning of the sequence of elements (public member function) |
|
(C++20) | returns the number of elements in the sequence (public member function) |
|
(C++20) | assigns a span (public member function) |
|
(C++17)(C++20) | returns the size of a container or array (function template) |
|
(C++17) | obtains the pointer to the underlying array (function template) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/container/span/span