std::span<T,Extent>::subspan

< cpp‎ | container‎ | span
template< std::size_t Offset,

          std::size_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::size_t Offset,

             std::size_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 greater than size();
  • Count is not std::dynamic_extent and 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)
obtains a subspan consisting of the last N elements of the sequence
(public member function)