HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
span< T, Extent > Class Template Reference

#include <span.h>

Public Types

using element_type = T
 
using value_type = typename std::remove_cv< T >::type
 
using size_type = oiio_span_size_type
 
using difference_type = ptrdiff_t
 
using pointer = element_type *
 
using reference = element_type &
 
using iterator = element_type *
 
using const_iterator = const element_type *
 
using reverse_iterator = std::reverse_iterator< iterator >
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 

Public Member Functions

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 > &copy) noexcept
 Copy constructor (copies the span pointer and length, NOT the data). More...
 
constexpr span (const span &copy) 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...
 
spanoperator= (const span &copy)
 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
 

Static Public Attributes

static constexpr size_type extent = Extent
 

Detailed Description

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.

Member Typedef Documentation

template<typename T, oiio_span_size_type Extent = dynamic_extent>
using span< T, Extent >::const_iterator = const element_type*

Definition at line 86 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
using span< T, Extent >::const_reverse_iterator = std::reverse_iterator<const_iterator>

Definition at line 88 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
using span< T, Extent >::difference_type = ptrdiff_t

Definition at line 79 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
using span< T, Extent >::element_type = T

Definition at line 76 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
using span< T, Extent >::iterator = element_type*

Definition at line 85 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
using span< T, Extent >::pointer = element_type*

Definition at line 83 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
using span< T, Extent >::reference = element_type&

Definition at line 84 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
using span< T, Extent >::reverse_iterator = std::reverse_iterator<iterator>

Definition at line 87 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
using span< T, Extent >::size_type = oiio_span_size_type

Definition at line 78 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
using span< T, Extent >::value_type = typename std::remove_cv<T>::type

Definition at line 77 of file span.h.

Constructor & Destructor Documentation

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr span< T, Extent >::span ( )
inlinenoexcept

Default constructor – the span points to nothing.

Definition at line 92 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
template<class U , oiio_span_size_type N>
constexpr span< T, Extent >::span ( const span< U, N > &  copy)
inlinenoexcept

Copy constructor (copies the span pointer and length, NOT the data).

Definition at line 96 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr span< T, Extent >::span ( const span< T, Extent > &  copy)
defaultnoexcept

Copy constructor (copies the span pointer and length, NOT the data).

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr span< T, Extent >::span ( pointer  data,
size_type  size 
)
inlinenoexcept

Construct from T* and length.

Definition at line 102 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr span< T, Extent >::span ( pointer  b,
pointer  e 
)
inlinenoexcept

Construct from begin and end pointers.

Definition at line 106 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr span< T, Extent >::span ( T data)
inline

Construct from a single T&.

Definition at line 110 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
template<size_t N>
constexpr span< T, Extent >::span ( T(&)  data[N])
inline

Construct from a fixed-length C array. Template magic automatically finds the length from the declared type of the array.

Definition at line 115 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
template<class Allocator >
constexpr span< T, Extent >::span ( std::vector< T, Allocator > &  v)
inline

Construct from std::vector<T>.

Definition at line 119 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
template<class Allocator >
span< T, Extent >::span ( const std::vector< value_type, Allocator > &  v)
inline

Construct from const std::vector<T>. This turns const std::vector<T> into a span<const T> (the span isn't const, but the data it points to will be).

Definition at line 127 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
template<size_t N>
constexpr span< T, Extent >::span ( std::array< value_type, N > &  arr)
inline

Construct from mutable element std::array.

Definition at line 132 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
template<size_t N>
constexpr span< T, Extent >::span ( const std::array< value_type, N > &  arr)
inline

Construct from read-only element std::array.

Definition at line 137 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr span< T, Extent >::span ( std::initializer_list< T il)
inline

Construct an span from an initializer_list.

Definition at line 141 of file span.h.

Member Function Documentation

template<typename T, oiio_span_size_type Extent = dynamic_extent>
reference span< T, Extent >::at ( size_type  idx) const
inline

Definition at line 193 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr reference span< T, Extent >::back ( void  ) const
inlinenoexcept

Definition at line 200 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr iterator span< T, Extent >::begin ( void  ) const
inlinenoexcept

Definition at line 202 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr const_iterator span< T, Extent >::cbegin ( ) const
inlinenoexcept

Definition at line 205 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr const_iterator span< T, Extent >::cend ( ) const
inlinenoexcept

Definition at line 206 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr const_reverse_iterator span< T, Extent >::crbegin ( ) const
inlinenoexcept

Definition at line 211 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr const_reverse_iterator span< T, Extent >::crend ( ) const
inlinenoexcept

Definition at line 212 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr pointer span< T, Extent >::data ( ) const
inlinenoexcept

Definition at line 189 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr bool span< T, Extent >::empty ( void  ) const
inlinenoexcept

Definition at line 187 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr iterator span< T, Extent >::end ( void  ) const
inlinenoexcept

Definition at line 203 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
template<size_type Count>
constexpr span<element_type, Count> span< T, Extent >::first ( ) const
inline

Subview containing the first Count elements of the span.

Definition at line 153 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr span<element_type, dynamic_extent> span< T, Extent >::first ( size_type  count) const
inline

Definition at line 167 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr reference span< T, Extent >::front ( void  ) const
inlinenoexcept

Definition at line 199 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
template<size_type Count>
constexpr span<element_type, Count> span< T, Extent >::last ( ) const
inline

Subview containing the last Count elements of the span.

Definition at line 158 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr span<element_type, dynamic_extent> span< T, Extent >::last ( size_type  count) const
inline

Definition at line 171 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr reference span< T, Extent >::operator() ( size_type  idx) const
inline

Definition at line 192 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
span& span< T, Extent >::operator= ( const span< T, Extent > &  copy)
inline

Assignment copies the pointer and length, not the data.

Definition at line 145 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr reference span< T, Extent >::operator[] ( size_type  idx) const
inline

Definition at line 191 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr reverse_iterator span< T, Extent >::rbegin ( ) const
inlinenoexcept

Definition at line 208 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr reverse_iterator span< T, Extent >::rend ( ) const
inlinenoexcept

Definition at line 209 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr size_type span< T, Extent >::size ( void  ) const
inlinenoexcept

Definition at line 185 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr size_type span< T, Extent >::size_bytes ( ) const
inlinenoexcept

Definition at line 186 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
template<size_type Offset, size_type Count = dynamic_extent>
constexpr span<element_type, Count> span< T, Extent >::subspan ( ) const
inline

Definition at line 163 of file span.h.

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr span<element_type, dynamic_extent> span< T, Extent >::subspan ( size_type  offset,
size_type  count = dynamic_extent 
) const
inline

Definition at line 176 of file span.h.

Member Data Documentation

template<typename T, oiio_span_size_type Extent = dynamic_extent>
constexpr size_type span< T, Extent >::extent = Extent
static

Definition at line 89 of file span.h.


The documentation for this class was generated from the following file: