W3cubDocs

/C++

std::span::subspan

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)
obtains a subspan consisting of the last N elements of the sequence
(public member function)

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/container/span/subspan