Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/container/span"

From cppreference.com
< cpp‎ | container
m (Verb agreement)
(Rename index_type to size_type)
Line 26: Line 26:
 
{{dsc | {{tt|element_type}} | {{tt|T}} }}
 
{{dsc | {{tt|element_type}} | {{tt|T}} }}
 
{{dsc | {{tt|value_type}} | {{c|std::remove_cv_t<T>}} }}
 
{{dsc | {{tt|value_type}} | {{c|std::remove_cv_t<T>}} }}
{{dsc | {{tt|index_type}} | {{lc|std::size_t}} }}
+
{{dsc | {{tt|size_type}} | {{lc|std::size_t}} }}
 
{{dsc | {{tt|difference_type}} | {{lc|std::ptrdiff_t}} }}
 
{{dsc | {{tt|difference_type}} | {{lc|std::ptrdiff_t}} }}
 
{{dsc | {{tt|pointer}} | {{tt|T*}} }}
 
{{dsc | {{tt|pointer}} | {{tt|T*}} }}

Revision as of 04:10, 2 December 2019

 
 
 
 
Defined in header <span>
template<

    class T,
    std::size_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

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

Member types

Member type Definition
element_type T
value_type std::remove_cv_t<T>
size_type std::size_t
difference_type std::ptrdiff_t
pointer T*
const_pointer const T*
reference T&
const_reference const T&
iterator implementation-defined LegacyRandomAccessIterator, ConstexprIterator, and LegacyContiguousIterator whose value_type is value_type
const_iterator implementation-defined constant LegacyRandomAccessIterator, ConstexprIterator, and LegacyContiguousIterator 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.

All requirements on the iterator types of a Container apply to the iterator and const_iterator types of span as well.

Member constant

static constexpr std::size_t extent = Extent;

Member functions

Template:cpp/container/span/dsc beginTemplate:cpp/container/span/dsc endTemplate:cpp/container/span/dsc rbeginTemplate:cpp/container/span/dsc rendorphaned, replaced with Template:cpp/container/dsc operator_at. orphaned, replaced with Template:cpp/container/dsc data.
constructs a span
(public member function) [edit]
assigns a span
(public member function) [edit]
Iterators
Element access
access the first element
(public member function) [edit]
access the last element
(public member function) [edit]
Observers
(C++20)
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]

Non-member functions

Template:cpp/container/span/dsc begin end nonmemTemplate:cpp/container/span/dsc get
converts a span into a view of its underlying bytes
(function template) [edit]

Non-member constant

a constant of type std::size_t signifying that the span has dynamic extent
(constant) [edit]

Helper classes

Template:cpp/container/span/dsc tuple sizeTemplate:cpp/container/span/dsc tuple element

Deduction guides