|
constexpr | span () noexcept |
| Default constructor – the span points to nothing. More...
|
|
template<class U , oiio_span_size_type N> |
constexpr | span (const span< U, N > ©) noexcept |
| Copy constructor (copies the span pointer and length, NOT the data). More...
|
|
constexpr | span (const span ©) noexcept=default |
| Copy constructor (copies the span pointer and length, NOT the data). More...
|
|
constexpr | span (pointer data, size_type size) noexcept |
| Construct from T* and length. More...
|
|
constexpr | span (pointer b, pointer e) noexcept |
| Construct from begin and end pointers. More...
|
|
constexpr | span (T &data) |
| Construct from a single T&. More...
|
|
template<size_t N> |
constexpr | span (T(&data)[N]) |
|
template<class Allocator > |
constexpr | span (std::vector< T, Allocator > &v) |
| Construct from std::vector<T>. More...
|
|
template<class Allocator > |
| span (const std::vector< value_type, Allocator > &v) |
|
template<size_t N> |
constexpr | span (std::array< value_type, N > &arr) |
| Construct from mutable element std::array. More...
|
|
template<size_t N> |
constexpr | span (const std::array< value_type, N > &arr) |
| Construct from read-only element std::array. More...
|
|
constexpr | span (std::initializer_list< T > il) |
| Construct an span from an initializer_list. More...
|
|
span & | operator= (const span ©) |
| Assignment copies the pointer and length, not the data. More...
|
|
template<size_type Count> |
constexpr span< element_type,
Count > | first () const |
| Subview containing the first Count elements of the span. More...
|
|
template<size_type Count> |
constexpr span< element_type,
Count > | last () const |
| Subview containing the last Count elements of the span. More...
|
|
template<size_type Offset, size_type Count = dynamic_extent> |
constexpr span< element_type,
Count > | subspan () const |
|
constexpr span< element_type,
dynamic_extent > | first (size_type count) const |
|
constexpr span< element_type,
dynamic_extent > | last (size_type count) const |
|
constexpr span< element_type,
dynamic_extent > | subspan (size_type offset, size_type count=dynamic_extent) const |
|
constexpr size_type | size () const noexcept |
|
constexpr size_type | size_bytes () const noexcept |
|
constexpr bool | empty () const noexcept |
|
constexpr pointer | data () const noexcept |
|
constexpr reference | operator[] (size_type idx) const |
|
constexpr reference | operator() (size_type idx) const |
|
reference | at (size_type idx) const |
|
constexpr reference | front () const noexcept |
|
constexpr reference | back () const noexcept |
|
constexpr iterator | begin () const noexcept |
|
constexpr iterator | end () const noexcept |
|
constexpr const_iterator | cbegin () const noexcept |
|
constexpr const_iterator | cend () const noexcept |
|
constexpr reverse_iterator | rbegin () const noexcept |
|
constexpr reverse_iterator | rend () const noexcept |
|
constexpr const_reverse_iterator | crbegin () const noexcept |
|
constexpr const_reverse_iterator | crend () const noexcept |
|
template<typename T, oiio_span_size_type Extent = dynamic_extent>
class span< T, Extent >
span<T> is a non-owning, non-copying, non-allocating reference to a contiguous array of T objects known length. A 'span` encapsulates both a pointer and a length, and thus is a safer way of passing pointers around (because the function called knows how long the array is). A function that might ordinarily take a T*
and a length could instead just take a span<T>
.
A span<T>
is mutable (the values in the array may be modified). A non-mutable (i.e., read-only) reference would be span<const T>
. Thus, a function that might ordinarily take a const T*
and a length could instead take a span<const T>
.
For convenience, we also define cspan<T>
as equivalent to span<const T>
.
A span
may be initialized explicitly from a pointer and length, by initializing with a std::vector<T>
, or by initalizing with a constant (treated as an array of length 1). For all of these cases, no extra allocations are performed, and no extra copies of the array contents are made.
Important caveat: The span
merely refers to items owned by another array, so the span
should not be used beyond the lifetime of the array it refers to. Thus, span
is great for parameter passing, but it's not a good idea to use a span
to store values in a data structure (unless you are really sure you know what you're doing).
Definition at line 73 of file span.h.