|
Represents a range of contiguous elements. More...
#include <span.h>
Public Types | |
using | element_type = T |
using | value_type = typename std::remove_cv< T >::type |
using | pointer = T * |
using | reference = T & |
using | index_type = std::size_t |
using | difference_type = std::ptrdiff_t |
using | iterator = T * |
using | const_iterator = const T * |
using | reverse_iterator = std::reverse_iterator< iterator > |
using | const_reverse_iterator = std::reverse_iterator< const_iterator > |
Public Member Functions | |
TfSpan (pointer ptr, index_type count) | |
Construct a span over the range of [ptr, ptr+count). | |
TfSpan (pointer first, pointer last) | |
Construct a span over the range [first, last). | |
template<class Container > | |
TfSpan (Container &cont, typename std::enable_if< !std::is_const< element_type >::value &&std::is_same< typename Container::value_type, value_type >::value, Container >::type *=0) | |
Construct a span from a container. | |
template<class Container > | |
TfSpan (const Container &cont, typename std::enable_if< std::is_same< typename Container::value_type, value_type >::value, Container >::type *=0) | |
Construct a span from a container. | |
pointer | data () const noexcept |
Return a pointer to the first element of the span. | |
index_type | size () const noexcept |
Return the total number of elements in the span. | |
bool | empty () const noexcept |
Returns true if this span contains no elements, false otherwise. | |
reference | operator[] (index_type idx) const |
Returns a reference to the idx'th element of the span. | |
reference | front () const |
Return a reference to the first element in the span. | |
reference | back () const |
Return a reference to the last element in the span. | |
iterator | begin () const noexcept |
Returns a non-const iterator the start of the span. | |
const_iterator | cbegin () const noexcept |
Returns a cons iterator to the start of the span. | |
iterator | end () const noexcept |
Returns a non-const iterator to the end of the span. | |
const_iterator | cend () const noexcept |
Returns a const iterator to the end of the span. | |
reverse_iterator | rbegin () const noexcept |
Returns a non-const reverse iterator the start of the span. | |
const_reverse_iterator | crbegin () const noexcept |
Returns a cons reverse iterator to the start of the span. | |
reverse_iterator | rend () const noexcept |
Returns a non-const reverse iterator to the end of the span. | |
const_reverse_iterator | crend () const noexcept |
Returns a const reverse iterator to the end of the span. | |
TfSpan< T > | subspan (difference_type offset, difference_type count=-1) const |
Returns a new span referencing a sub-range of this span. | |
TfSpan< T > | first (size_t count) const |
Return a subspan consisting of the first count elements of this span. | |
TfSpan< T > | last (size_t count) const |
Return a subspan consisting of the last count elements of this span. | |
Represents a range of contiguous elements.
This simply pairs a pointer with a size, while adding a common array interface.
A span allows ranges of elements to be referenced in a container-neutral manner. While it is possible to achieve that effect by simply passing around raw pointers, a span has the advantage of carrying around additional size information, both enabling use of common array patterns, as well as providing sufficient information to perform boundary tests.
A TfSpan is implicitly convertible from common array types, as well as from other spans, but preserves const-ness:
Helper methods TfMakeSpan and TfMakeConstSpan are also provided to enable auto-typing when constructing spans:
Spans do not own the data they reference. It is up to the user of the span to ensure that the underlying data is not destructed while the span is in use.
This is modelled after std::span (C++20), but does not currently include any specialization for static extents.
using const_reverse_iterator = std::reverse_iterator<const_iterator> |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |