Difference between revisions of "cpp/container/span/subspan"
From cppreference.com
m |
m (link to zh) |
||
Line 34: | Line 34: | ||
{{dsc inc | cpp/container/span/dsc last}} | {{dsc inc | cpp/container/span/dsc last}} | ||
{{dsc end}} | {{dsc end}} | ||
+ | |||
+ | {{langlinks|zh}} |
Revision as of 18:03, 19 March 2018
template< std::ptrdiff_t Offset, std::ptrdiff_t Count = std::dynamic_extent > |
(1) | |
constexpr std::span<element_type, std::dynamic_extent> subspan( std::ptrdiff_t Offset, |
(2) | |
Obtains a span that is a view over the Count
elements of this span starting at offset Offset
. If Count
is std::dynamic_extent
, the number of elements in the subspan is size() - offset
(i.e., it ends at the end of *this
.).
The behavior is undefined if either Offset
or Count
is out of range. This happens if
-
Offset
is either less than zero or greater thansize()
; -
Count
is less than zero and notstd::dynamic_extent
; -
Offset + Count
is greater thansize()
.
The extent E
of the span returned by (1) is determined as follows:
- If
Count
is notstd::dynamic_extent
,Count
; - Otherwise, if
Extent
is notstd::dynamic_extent
,Extent - Offset
; - Otherwise,
std::dynamic_extent
.
Return value
The requested subspan r
, such that r.data() == this->data() + Offset. If Count
is std::dynamic_extent
, r.size() == this->size() - Offset; otherwise r.size() == Count.
See also
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) |