Zserio C++ runtime library  1.0.2
Built for Zserio 2.14.1
zserio::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 = std::size_t
 
using difference_type = std::ptrdiff_t
 
using pointer = T *
 
using const_pointer = const T *
 
using reference = T &
 
using iterator = pointer
 
using const_iterator = const_pointer
 
using reverse_iterator = std::reverse_iterator< iterator >
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 
template<size_type Offset, size_type Count>
using SubspanReturnType = Span< T, Count !=dynamic_extent ? Count :(Extent !=dynamic_extent ? Extent - Offset :dynamic_extent)>
 

Public Member Functions

template<size_type ext = Extent, typename std::enable_if<(ext==0||ext==dynamic_extent), int >::type = 0>
constexpr Span () noexcept
 
constexpr Span (pointer first_, size_type count)
 
constexpr Span (pointer first_, pointer last_)
 
template<size_type N, size_type ext = Extent, typename std::enable_if<(ext==dynamic_extent||ext==N), int >::type = 0>
constexpr Span (element_type(&arr)[N]) noexcept
 
template<typename U , size_type N, size_type ext = Extent, typename std::enable_if<(ext==dynamic_extent||ext==N) &&std::is_convertible< U(*)[], T(*)[]>::value, int >::type = 0>
constexpr Span (std::array< U, N > &arr) noexcept
 
template<typename U , size_type N, size_type ext = Extent, typename std::enable_if<(ext==dynamic_extent||ext==N) &&std::is_convertible< const U(*)[], T(*)[]>::value, int >::type = 0>
constexpr Span (const std::array< U, N > &arr) noexcept
 
template<typename U , typename ALLOC , size_type ext = Extent, typename std::enable_if<(ext==dynamic_extent) &&std::is_convertible< U(*)[], T(*)[]>::value, int >::type = 0>
constexpr Span (std::vector< U, ALLOC > &vec)
 
template<typename U , typename ALLOC , size_type ext = Extent, typename std::enable_if<(ext==dynamic_extent) &&std::is_convertible< const U(*)[], T(*)[]>::value, int >::type = 0>
constexpr Span (const std::vector< U, ALLOC > &vec)
 
template<typename U , size_type N, typename std::enable_if<(Extent==N||Extent==dynamic_extent) &&std::is_convertible< U(*)[], T(*)[]>::value, int >::type = 0>
constexpr Span (const Span< U, N > &span) noexcept
 
constexpr iterator begin () const noexcept
 
constexpr iterator end () const noexcept
 
constexpr reverse_iterator rbegin () const noexcept
 
constexpr reverse_iterator rend () const noexcept
 
constexpr reference front () const
 
constexpr reference back () const
 
constexpr reference operator[] (size_type idx) const
 
constexpr pointer data () const noexcept
 
constexpr size_type size () const noexcept
 
constexpr size_type size_bytes () const noexcept
 
constexpr bool empty () const noexcept
 
template<size_type Count>
constexpr Span< element_type, Count > first () const
 
constexpr Span< element_type, dynamic_extentfirst (size_type Count) const
 
template<size_type Count>
constexpr Span< element_type, Count > last () const
 
constexpr Span< element_type, dynamic_extentlast (size_type Count) const
 
constexpr Span< element_type, dynamic_extentsubspan (size_type Offset, size_type Count=dynamic_extent) const
 
 ~Span ()=default
 
 Span (const Span &other) noexcept=default
 
Spanoperator= (const Span &other) noexcept=default
 
 Span (Span &&other) noexcept=default
 
Spanoperator= (Span &&other) noexcept=default
 
template<size_type Offset, size_type Count = dynamic_extent, typename std::enable_if< Count==dynamic_extent, int >::type = 0>
constexpr SubspanReturnType< Offset, Count > subspan () const
 
template<size_type Offset, size_type Count, typename std::enable_if< Count !=dynamic_extent, int >::type = 0>
constexpr SubspanReturnType< Offset, Count > subspan () const
 

Static Public Attributes

static constexpr size_type extent = Extent
 

Detailed Description

template<typename T, std::size_t Extent = dynamic_extent>
class zserio::Span< T, Extent >

Class that holds non-owning reference (aka. "view") to continuous sequence of objects. The user of this class is responsible of making sure, that the referenced sequence is valid as long as the instance of the Span is alive. Inspired by C++20 std::span.

Definition at line 58 of file Span.h.

Member Typedef Documentation

◆ const_iterator

template<typename T , std::size_t Extent = dynamic_extent>
using zserio::Span< T, Extent >::const_iterator = const_pointer

Definition at line 69 of file Span.h.

◆ const_pointer

template<typename T , std::size_t Extent = dynamic_extent>
using zserio::Span< T, Extent >::const_pointer = const T*

Definition at line 66 of file Span.h.

◆ const_reverse_iterator

template<typename T , std::size_t Extent = dynamic_extent>
using zserio::Span< T, Extent >::const_reverse_iterator = std::reverse_iterator<const_iterator>

Definition at line 71 of file Span.h.

◆ difference_type

template<typename T , std::size_t Extent = dynamic_extent>
using zserio::Span< T, Extent >::difference_type = std::ptrdiff_t

Definition at line 64 of file Span.h.

◆ element_type

template<typename T , std::size_t Extent = dynamic_extent>
using zserio::Span< T, Extent >::element_type = T

Definition at line 61 of file Span.h.

◆ iterator

template<typename T , std::size_t Extent = dynamic_extent>
using zserio::Span< T, Extent >::iterator = pointer

Definition at line 68 of file Span.h.

◆ pointer

template<typename T , std::size_t Extent = dynamic_extent>
using zserio::Span< T, Extent >::pointer = T*

Definition at line 65 of file Span.h.

◆ reference

template<typename T , std::size_t Extent = dynamic_extent>
using zserio::Span< T, Extent >::reference = T&

Definition at line 67 of file Span.h.

◆ reverse_iterator

template<typename T , std::size_t Extent = dynamic_extent>
using zserio::Span< T, Extent >::reverse_iterator = std::reverse_iterator<iterator>

Definition at line 70 of file Span.h.

◆ size_type

template<typename T , std::size_t Extent = dynamic_extent>
using zserio::Span< T, Extent >::size_type = std::size_t

Definition at line 63 of file Span.h.

◆ SubspanReturnType

template<typename T , std::size_t Extent = dynamic_extent>
template<size_type Offset, size_type Count>
using zserio::Span< T, Extent >::SubspanReturnType = Span<T, Count != dynamic_extent ? Count : (Extent != dynamic_extent ? Extent - Offset : dynamic_extent)>

Definition at line 353 of file Span.h.

◆ value_type

template<typename T , std::size_t Extent = dynamic_extent>
using zserio::Span< T, Extent >::value_type = typename std::remove_cv<T>::type

Definition at line 62 of file Span.h.

Constructor & Destructor Documentation

◆ Span() [1/11]

template<typename T , std::size_t Extent = dynamic_extent>
template<size_type ext = Extent, typename std::enable_if<(ext==0||ext==dynamic_extent), int >::type = 0>
constexpr zserio::Span< T, Extent >::Span ( )
inlineconstexprnoexcept

Constructor. Initializes empty Span.

Definition at line 80 of file Span.h.

◆ Span() [2/11]

template<typename T , std::size_t Extent = dynamic_extent>
constexpr zserio::Span< T, Extent >::Span ( pointer  first_,
size_type  count 
)
inlineconstexpr

Constructor. Initializes Span holding a reference starting at given pointer, having given number of elements.

Parameters
first_Pointer to first element in the sequence.
countNumber of elements.

Definition at line 90 of file Span.h.

◆ Span() [3/11]

template<typename T , std::size_t Extent = dynamic_extent>
constexpr zserio::Span< T, Extent >::Span ( pointer  first_,
pointer  last_ 
)
inlineconstexpr

Constructor. Initializes Span holding a reference starting at given pointer, ending at another pointer.

Parameters
first_Pointer to first element in the sequence.
last_Pointer to one-after-last element in the sequence.

Definition at line 101 of file Span.h.

◆ Span() [4/11]

template<typename T , std::size_t Extent = dynamic_extent>
template<size_type N, size_type ext = Extent, typename std::enable_if<(ext==dynamic_extent||ext==N), int >::type = 0>
constexpr zserio::Span< T, Extent >::Span ( element_type(&)  arr[N])
inlineconstexprnoexcept

Constructor. Initializes Span holding a reference to array.

Parameters
arrArray to which the Span will hold a reference.

Definition at line 112 of file Span.h.

◆ Span() [5/11]

template<typename T , std::size_t Extent = dynamic_extent>
template<typename U , size_type N, size_type ext = Extent, typename std::enable_if<(ext==dynamic_extent||ext==N) &&std::is_convertible< U(*)[], T(*)[]>::value, int >::type = 0>
constexpr zserio::Span< T, Extent >::Span ( std::array< U, N > &  arr)
inlineconstexprnoexcept

Constructor. Initializes Span holding a reference to std::array.

Parameters
arrstd::array to which the Span will hold a reference.

Definition at line 125 of file Span.h.

◆ Span() [6/11]

template<typename T , std::size_t Extent = dynamic_extent>
template<typename U , size_type N, size_type ext = Extent, typename std::enable_if<(ext==dynamic_extent||ext==N) &&std::is_convertible< const U(*)[], T(*)[]>::value, int >::type = 0>
constexpr zserio::Span< T, Extent >::Span ( const std::array< U, N > &  arr)
inlineconstexprnoexcept

Constructor. Initializes Span holding a reference to std::array.

Parameters
arrstd::array to which the Span will hold a reference.

Definition at line 138 of file Span.h.

◆ Span() [7/11]

template<typename T , std::size_t Extent = dynamic_extent>
template<typename U , typename ALLOC , size_type ext = Extent, typename std::enable_if<(ext==dynamic_extent) &&std::is_convertible< U(*)[], T(*)[]>::value, int >::type = 0>
constexpr zserio::Span< T, Extent >::Span ( std::vector< U, ALLOC > &  vec)
inlineconstexpr

Constructor. Initializes Span holding a reference to std::vector.

Parameters
vecstd::vector to which the Span will hold a reference.

Definition at line 150 of file Span.h.

◆ Span() [8/11]

template<typename T , std::size_t Extent = dynamic_extent>
template<typename U , typename ALLOC , size_type ext = Extent, typename std::enable_if<(ext==dynamic_extent) &&std::is_convertible< const U(*)[], T(*)[]>::value, int >::type = 0>
constexpr zserio::Span< T, Extent >::Span ( const std::vector< U, ALLOC > &  vec)
inlineconstexpr

Constructor. Initializes Span holding a reference to std::vector.

Parameters
vecstd::vector to which the Span will hold a reference.

Definition at line 163 of file Span.h.

◆ Span() [9/11]

template<typename T , std::size_t Extent = dynamic_extent>
template<typename U , size_type N, typename std::enable_if<(Extent==N||Extent==dynamic_extent) &&std::is_convertible< U(*)[], T(*)[]>::value, int >::type = 0>
constexpr zserio::Span< T, Extent >::Span ( const Span< U, N > &  span)
inlineconstexprnoexcept

Constructor. Convert between spans of different types.

Parameters
spanInput span.

Definition at line 176 of file Span.h.

◆ ~Span()

template<typename T , std::size_t Extent = dynamic_extent>
zserio::Span< T, Extent >::~Span ( )
default

Method generated by default.

◆ Span() [10/11]

template<typename T , std::size_t Extent = dynamic_extent>
zserio::Span< T, Extent >::Span ( const Span< T, Extent > &  other)
defaultnoexcept

Method generated by default.

◆ Span() [11/11]

template<typename T , std::size_t Extent = dynamic_extent>
zserio::Span< T, Extent >::Span ( Span< T, Extent > &&  other)
defaultnoexcept

Method generated by default.

Member Function Documentation

◆ back()

template<typename T , std::size_t Extent = dynamic_extent>
constexpr reference zserio::Span< T, Extent >::back ( ) const
inlineconstexpr

Get reference to the last element of the sequence. The sequence shall not be empty.

Returns
Reference to the last element of the sequence

Definition at line 250 of file Span.h.

◆ begin()

template<typename T , std::size_t Extent = dynamic_extent>
constexpr iterator zserio::Span< T, Extent >::begin ( ) const
inlineconstexprnoexcept

Begin iteration.

Returns
Iterator to the beginning of the sequence.

Definition at line 200 of file Span.h.

◆ data()

template<typename T , std::size_t Extent = dynamic_extent>
constexpr pointer zserio::Span< T, Extent >::data ( ) const
inlineconstexprnoexcept

Get pointer to the sequence beginning.

Returns
Pointer to the sequence beginning

Definition at line 271 of file Span.h.

◆ empty()

template<typename T , std::size_t Extent = dynamic_extent>
constexpr bool zserio::Span< T, Extent >::empty ( ) const
inlineconstexprnoexcept

Check if the sequence is empty.

Returns
True if the sequence is empty, false otherwise.

Definition at line 301 of file Span.h.

◆ end()

template<typename T , std::size_t Extent = dynamic_extent>
constexpr iterator zserio::Span< T, Extent >::end ( ) const
inlineconstexprnoexcept

End iteration.

Returns
Iterator one-past-last element of the sequence.

Definition at line 210 of file Span.h.

◆ first() [1/2]

template<typename T , std::size_t Extent = dynamic_extent>
template<size_type Count>
constexpr Span<element_type, Count> zserio::Span< T, Extent >::first ( ) const
inlineconstexpr

Get subspan of given number of elements from the sequence start.

Returns
Subspan of given number of elements from the sequence start.

Definition at line 312 of file Span.h.

◆ first() [2/2]

template<typename T , std::size_t Extent = dynamic_extent>
constexpr Span<element_type, dynamic_extent> zserio::Span< T, Extent >::first ( size_type  Count) const
inlineconstexpr

Get subspan of given number of elements from the sequence start.

Parameters
CountRequested number of elements in the subspan. Shall not be bigger than size().
Returns
Subspan of given number of elements from the sequence start.

Definition at line 324 of file Span.h.

◆ front()

template<typename T , std::size_t Extent = dynamic_extent>
constexpr reference zserio::Span< T, Extent >::front ( ) const
inlineconstexpr

Get reference to the first element of the sequence. The sequence shall not be empty.

Returns
Reference to the first element of the sequence

Definition at line 240 of file Span.h.

◆ last() [1/2]

template<typename T , std::size_t Extent = dynamic_extent>
template<size_type Count>
constexpr Span<element_type, Count> zserio::Span< T, Extent >::last ( ) const
inlineconstexpr

Get subspan of given number of elements from the sequence end.

Returns
Subspan of given number of elements from the sequence end.

Definition at line 335 of file Span.h.

◆ last() [2/2]

template<typename T , std::size_t Extent = dynamic_extent>
constexpr Span<element_type, dynamic_extent> zserio::Span< T, Extent >::last ( size_type  Count) const
inlineconstexpr

Get subspan of given number of elements from the sequence end.

Parameters
CountRequested number of elements in the subspan. Shall not be bigger than size().
Returns
Subspan of given number of elements from the sequence end.

Definition at line 347 of file Span.h.

◆ operator=() [1/2]

template<typename T , std::size_t Extent = dynamic_extent>
Span& zserio::Span< T, Extent >::operator= ( const Span< T, Extent > &  other)
defaultnoexcept

Method generated by default.

◆ operator=() [2/2]

template<typename T , std::size_t Extent = dynamic_extent>
Span& zserio::Span< T, Extent >::operator= ( Span< T, Extent > &&  other)
defaultnoexcept

Method generated by default.

◆ operator[]()

template<typename T , std::size_t Extent = dynamic_extent>
constexpr reference zserio::Span< T, Extent >::operator[] ( size_type  idx) const
inlineconstexpr

Access the element on given index.

Parameters
idxIndex of element to be accessed. Must be less than size().
Returns
Element on given index.

Definition at line 261 of file Span.h.

◆ rbegin()

template<typename T , std::size_t Extent = dynamic_extent>
constexpr reverse_iterator zserio::Span< T, Extent >::rbegin ( ) const
inlineconstexprnoexcept

Begin reverse iteration.

Returns
Reverse iterator to the last element.

Definition at line 220 of file Span.h.

◆ rend()

template<typename T , std::size_t Extent = dynamic_extent>
constexpr reverse_iterator zserio::Span< T, Extent >::rend ( ) const
inlineconstexprnoexcept

End reverse iteration.

Returns
Reverse iterator one-before-first element of the sequence.

Definition at line 230 of file Span.h.

◆ size()

template<typename T , std::size_t Extent = dynamic_extent>
constexpr size_type zserio::Span< T, Extent >::size ( ) const
inlineconstexprnoexcept

Get number of elements in the sequence.

Returns
Number of elements in the sequence.

Definition at line 281 of file Span.h.

◆ size_bytes()

template<typename T , std::size_t Extent = dynamic_extent>
constexpr size_type zserio::Span< T, Extent >::size_bytes ( ) const
inlineconstexprnoexcept

Get size of sequence in bytes.

Returns
Size of sequence in bytes.

Definition at line 291 of file Span.h.

◆ subspan() [1/3]

template<typename T , std::size_t Extent = dynamic_extent>
template<size_type Offset, size_type Count = dynamic_extent, typename std::enable_if< Count==dynamic_extent, int >::type = 0>
constexpr SubspanReturnType<Offset, Count> zserio::Span< T, Extent >::subspan ( ) const
inlineconstexpr

Get subspan of given number of elements beginning at given index.

Returns
Subspan of given number of elements beginning at given index.

Definition at line 364 of file Span.h.

◆ subspan() [2/3]

template<typename T , std::size_t Extent = dynamic_extent>
template<size_type Offset, size_type Count, typename std::enable_if< Count !=dynamic_extent, int >::type = 0>
constexpr SubspanReturnType<Offset, Count> zserio::Span< T, Extent >::subspan ( ) const
inlineconstexpr

Get subspan of given number of elements beginning at given index.

Returns
Subspan of given number of elements beginning at given index.

Definition at line 373 of file Span.h.

◆ subspan() [3/3]

template<typename T , std::size_t Extent = dynamic_extent>
constexpr Span<element_type, dynamic_extent> zserio::Span< T, Extent >::subspan ( size_type  Offset,
size_type  Count = dynamic_extent 
) const
inlineconstexpr

Get subspan of given number of elements beginning at given index.

Parameters
OffsetIndex in the original sequence, where the new subspan should start
CountRequested number of elements in the subspan.
Returns
Subspan of given number of elements beginning at given index.

Definition at line 388 of file Span.h.

Member Data Documentation

◆ extent

template<typename T , std::size_t Extent = dynamic_extent>
constexpr size_type zserio::Span< T, Extent >::extent = Extent
staticconstexpr

Definition at line 73 of file Span.h.


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