Namespaces
Variants
Views
Actions

std::span

From cppreference.com
< cpp‎ | container
Defined in header <span>
inline constexpr std::ptrdiff_t dynamic_extent = -1;
(since C++20)
template<

    class T,
    std::ptrdiff_t Extent = std::dynamic_extent

> class span;
(since C++20)

The class template span describes an object that can refer to a contiguous sequence of objects with the first element of the sequence at position zero. A span can either have a static extent, in which case the number of elements in the sequence is known and encoded in the type, or a dynamic extent.

A typical implementation holds only two members: a pointer to T and a size.

Contents

[edit] Template parameters

T - element type; must be a complete type that is not an abstract class type
Extent - the number of elements in the sequence, or std::dynamic_extent if dynamic; the program is ill-formed if Extent is negative and is not std::dynamic_extent

[edit] Member types

Member type Definition
element_type T
value_type std::remove_cv_t<T>
index_type std::ptrdiff_t
difference_type std::ptrdiff_t
pointer T*
reference T&
iterator implementation-defined RandomAccessIterator and ContiguousIterator whose value_type is value_type
const_iterator implementation-defined constant RandomAccessIterator and ContiguousIterator whose value_type is value_type
reverse_iterator std::reverse_iterator<iterator>
const_reverse_iterator std::reverse_iterator<const_iterator>

Note: iterator is a mutable iterator if T is not const-qualified.

[edit] Member constant

static constexpr std::ptrdiff_t extent = Extent;

[edit] Member functions

constructs a span
(public member function) [edit]
assigns a span
(public member function) [edit]
Iterators
returns an iterator to the beginning of the sequence
(public member function) [edit]
returns an iterator to the end of the sequence
(public member function) [edit]
returns a reverse iterator to the beginning of the sequence
(public member function) [edit]
returns a reverse iterator to the end of the sequence
(public member function) [edit]
Element access
accesses an element of the sequence
(public member function) [edit]
returns a pointer to the beginning of the sequence of elements
(public member function) [edit]
Observers
returns the number of elements in the sequence
(public member function) [edit]
returns the size of the sequence in bytes
(public member function) [edit]
checks if the sequence is empty
(public member function) [edit]
Subviews
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]
obtains a subspan
(public member function) [edit]

[edit] Non-member functions

compares the elements of two spans
(function template) [edit]
converts a span into a view of its underlying bytes
(function template) [edit]

[edit] Non-member constant

a constant of type ptrdiff_t
(constant) [edit]

[edit] Deduction guides