Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/container/span/subspan"

From cppreference.com
< cpp‎ | container‎ | span
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 >

constexpr std::span<element_type, E /* see below */> subspan() const;
(1)
constexpr std::span<element_type, std::dynamic_extent>

    subspan( std::ptrdiff_t Offset,

             std::ptrdiff_t Count = std::dynamic_extent ) const;
(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 than size();
  • Count is less than zero and not std::dynamic_extent;
  • Offset + Count is greater than size().

The extent E of the span returned by (1) is determined as follows:

  • If Count is not std::dynamic_extent, Count;
  • Otherwise, if Extent is not std::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) [edit]
obtains a subspan consisting of the last N elements of the sequence
(public member function) [edit]