C++ - Span
Table of Contents
std::span is a class template introduced in C++ 20. As one of the most paramount features, span is essentially a non-owning view of a sequence of objects, which is contiguously distributed in memory and can consequently be iterated and indexed, e.g., std::array, std::vector, std::string.
Constructors
span(ptr)span(ptr, len)span(starting_ptr, ending_ptr)
Member functions
first(num)returns a new span comprising the firstnumelements.last(num)returns a new span comprising the lastnumelements.front()/data()returns a reference to the first element.back()returns a reference to the last element.at(idx)/operator[idx]returns a reference to theidxth element.subspan(starting_idx, len)returns a new span of lengthlenstarting fromstarting_idxth element.size()returns the number of elements in the span.empty()returns a boolean indicator whether the span is empty.begin()returns the iterator to the beginning of the span.end()returns the iterator to the ending (sentinel) of the span.