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 index_type = ptrdiff_t
 
using difference_type = ptrdiff_t
 
using size_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 ctr – points to nothing. More...
 
template<class U , ptrdiff_t N>
constexpr span (const span< U, N > &copy) noexcept
 Copy constructor. More...
 
constexpr span (const span &copy) noexcept=default
 
constexpr span (pointer data, index_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])
 
constexpr span (std::vector< T > &v)
 Construct from std::vector<T>. More...
 
 span (const std::vector< value_type > &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)
 
template<index_type Count>
constexpr span< element_type,
Count > 
first () const
 
template<index_type Count>
constexpr span< element_type,
Count > 
last () const
 
template<index_type Offset, index_type Count = dynamic_extent>
constexpr span< element_type,
Count > 
subspan () const
 
constexpr span< element_type,
dynamic_extent
first (index_type count) const
 
constexpr span< element_type,
dynamic_extent
last (index_type count) const
 
constexpr span< element_type,
dynamic_extent
subspan (index_type offset, index_type count=dynamic_extent) const
 
constexpr index_type size () const noexcept
 
constexpr index_type size_bytes () const noexcept
 
constexpr bool empty () const noexcept
 
constexpr pointer data () const noexcept
 
constexpr reference operator[] (index_type idx) const
 
constexpr reference operator() (index_type idx) const
 
reference at (index_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 index_type extent = Extent
 

Detailed Description

template<typename T, ptrdiff_t Extent = dynamic_extent>
class span< T, Extent >

span<T> : a non-owning reference to a contiguous array with known length. An span<T> is mutable (the values in the array may be modified), whereas an span<const T> is not mutable.

Background: Functions whose input requires a set of contiguous values (an array) are faced with a dilemma. If the caller passes just a pointer, the function has no inherent way to determine how many elements may safely be accessed. Passing a std::vector& is "safe", but the caller may not have the data in a vector. The function could require an explicit length to be passed (or a begin/end pair of iterators or pointers). Any way you shake it, there is some awkwardness.

The span template tries to address this problem by providing a way to pass array parameters that are non-owning, non-copying, non-allocating, and contain a length reference (which in many cases is transparently and automatically computed without additional user code).

Definition at line 47 of file span.h.

Member Typedef Documentation

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

Definition at line 58 of file span.h.

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

Definition at line 60 of file span.h.

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

Definition at line 53 of file span.h.

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

Definition at line 50 of file span.h.

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

Definition at line 52 of file span.h.

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

Definition at line 57 of file span.h.

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

Definition at line 55 of file span.h.

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

Definition at line 56 of file span.h.

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

Definition at line 59 of file span.h.

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

Definition at line 54 of file span.h.

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

Definition at line 51 of file span.h.

Constructor & Destructor Documentation

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

Default ctr – points to nothing.

Definition at line 64 of file span.h.

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

Copy constructor.

Definition at line 68 of file span.h.

template<typename T, ptrdiff_t Extent = dynamic_extent>
constexpr span< T, Extent >::span ( const span< T, Extent > &  copy)
defaultnoexcept
template<typename T, ptrdiff_t Extent = dynamic_extent>
constexpr span< T, Extent >::span ( pointer  data,
index_type  size 
)
inlinenoexcept

Construct from T* and length.

Definition at line 73 of file span.h.

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

Construct from begin and end pointers.

Definition at line 77 of file span.h.

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

Construct from a single T&.

Definition at line 81 of file span.h.

template<typename T, ptrdiff_t 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 86 of file span.h.

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

Construct from std::vector<T>.

Definition at line 89 of file span.h.

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

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

Definition at line 96 of file span.h.

template<typename T, ptrdiff_t 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 101 of file span.h.

template<typename T, ptrdiff_t 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 106 of file span.h.

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

Construct an span from an initializer_list.

Definition at line 110 of file span.h.

Member Function Documentation

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

Definition at line 156 of file span.h.

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

Definition at line 163 of file span.h.

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

Definition at line 165 of file span.h.

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

Definition at line 168 of file span.h.

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

Definition at line 169 of file span.h.

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

Definition at line 174 of file span.h.

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

Definition at line 175 of file span.h.

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

Definition at line 152 of file span.h.

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

Definition at line 150 of file span.h.

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

Definition at line 166 of file span.h.

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

Definition at line 122 of file span.h.

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

Definition at line 135 of file span.h.

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

Definition at line 162 of file span.h.

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

Definition at line 126 of file span.h.

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

Definition at line 139 of file span.h.

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

Definition at line 155 of file span.h.

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

Definition at line 114 of file span.h.

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

Definition at line 154 of file span.h.

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

Definition at line 171 of file span.h.

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

Definition at line 172 of file span.h.

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

Definition at line 148 of file span.h.

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

Definition at line 149 of file span.h.

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

Definition at line 131 of file span.h.

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

Definition at line 144 of file span.h.

Member Data Documentation

template<typename T, ptrdiff_t Extent = dynamic_extent>
constexpr index_type span< T, Extent >::extent = Extent
static

Definition at line 61 of file span.h.


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