libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
Span< T > Class Template Reference

Non-owning view over contiguous storage, wrapping std::span. More...

#include <span.h>

Public Types

using Iterator = typename std::span< T >::iterator
 Mutable forward iterator.
 
using ConstIterator = typename std::span< const T >::iterator
 Const forward iterator.
 
using RevIterator = typename std::span< T >::reverse_iterator
 Mutable reverse iterator.
 
using ConstRevIterator = typename std::span< const T >::reverse_iterator
 Const reverse iterator.
 

Public Member Functions

 Span ()=default
 Default constructor. Creates an empty span.
 
 Span (T *ptr, size_t count)
 Constructs a span from a pointer and size.
 
 Span (List< T > &list)
 Constructs a span from a List.
 
template<size_t N>
 Span (T(&arr)[N])
 Constructs a span from a C array.
 
template<size_t N>
 Span (Array< T, N > &arr)
 Constructs a span from an Array.
 
 Span (const Span &other)=default
 Copy constructor.
 
Spanoperator= (const Span &other)=default
 Copy assignment operator.
 
Iterator begin () noexcept
 Returns a mutable iterator to the first element.
 
ConstIterator begin () const noexcept
 Returns a const iterator to the first element.
 
Iterator end () noexcept
 Returns a mutable iterator to one past the last element.
 
ConstIterator end () const noexcept
 Returns a const iterator to one past the last element.
 
ConstIterator constBegin () const noexcept
 Returns a const iterator to the first element.
 
ConstIterator constEnd () const noexcept
 Returns a const iterator to one past the last element.
 
RevIterator rbegin () noexcept
 Returns a mutable reverse iterator to the last element.
 
RevIterator revBegin () noexcept
 Returns a mutable reverse iterator to the last element.
 
RevIterator rend () noexcept
 Returns a mutable reverse iterator to one before the first element.
 
RevIterator revEnd () noexcept
 Returns a mutable reverse iterator to one before the first element.
 
ConstRevIterator crbegin () const noexcept
 Returns a const reverse iterator to the last element.
 
ConstRevIterator constRevBegin () const noexcept
 Returns a const reverse iterator to the last element.
 
ConstRevIterator crend () const noexcept
 Returns a const reverse iterator to one before the first element.
 
ConstRevIterator constRevEnd () const noexcept
 Returns a const reverse iterator to one before the first element.
 
Toperator[] (size_t index)
 Returns a reference to the element at index without bounds checking.
 
const Toperator[] (size_t index) const
 Returns a reference to the element at index without bounds checking.
 
Tfront ()
 Returns a reference to the first element.
 
const Tfront () const
 Returns a reference to the first element.
 
Tback ()
 Returns a reference to the last element.
 
const Tback () const
 Returns a reference to the last element.
 
Tdata () noexcept
 Returns a pointer to the underlying contiguous storage.
 
const Tdata () const noexcept
 Returns a pointer to the underlying contiguous storage.
 
bool isEmpty () const noexcept
 Returns true if the span has no elements.
 
size_t size () const noexcept
 Returns the number of elements.
 
size_t sizeBytes () const noexcept
 Returns the size in bytes.
 
Span subspan (size_t offset, size_t count)
 Returns a sub-span starting at offset with count elements.
 
Span first (size_t count)
 Returns a span of the first count elements.
 
Span last (size_t count)
 Returns a span of the last count elements.
 
template<typename Func >
void forEach (Func &&func) const
 Calls func for every element.
 

Detailed Description

template<typename T>
class Span< T >

Non-owning view over contiguous storage, wrapping std::span.

Provides a Qt-inspired API over std::span with consistent naming conventions matching the rest of libpromeki. Non-owning view — no PROMEKI_SHARED_FINAL.

Template Parameters
TElement type.

Constructor & Destructor Documentation

◆ Span() [1/4]

template<typename T >
Span< T >::Span ( T ptr,
size_t  count 
)
inline

Constructs a span from a pointer and size.

Parameters
ptrPointer to the first element.
countNumber of elements.

◆ Span() [2/4]

template<typename T >
Span< T >::Span ( List< T > &  list)
inline

Constructs a span from a List.

Parameters
listThe list to view.

◆ Span() [3/4]

template<typename T >
template<size_t N>
Span< T >::Span ( T(&)  arr[N])
inline

Constructs a span from a C array.

Template Parameters
NArray size.
Parameters
arrThe C array to view.

◆ Span() [4/4]

template<typename T >
template<size_t N>
Span< T >::Span ( Array< T, N > &  arr)
inline

Constructs a span from an Array.

Template Parameters
NArray size.
Parameters
arrThe Array to view.

Member Function Documentation

◆ back()

template<typename T >
const T & Span< T >::back ( ) const
inline

Returns a reference to the last element.

◆ constRevBegin()

template<typename T >
ConstRevIterator Span< T >::constRevBegin ( ) const
inlinenoexcept

Returns a const reverse iterator to the last element.

◆ constRevEnd()

template<typename T >
ConstRevIterator Span< T >::constRevEnd ( ) const
inlinenoexcept

Returns a const reverse iterator to one before the first element.

◆ data()

template<typename T >
const T * Span< T >::data ( ) const
inlinenoexcept

Returns a pointer to the underlying contiguous storage.

◆ first()

template<typename T >
Span Span< T >::first ( size_t  count)
inline

Returns a span of the first count elements.

Parameters
countNumber of elements.
Returns
A new Span viewing the first elements.

◆ forEach()

template<typename T >
template<typename Func >
void Span< T >::forEach ( Func &&  func) const
inline

Calls func for every element.

Template Parameters
FuncCallable with signature void(const T &).
Parameters
funcThe function to invoke.

◆ front()

template<typename T >
const T & Span< T >::front ( ) const
inline

Returns a reference to the first element.

◆ last()

template<typename T >
Span Span< T >::last ( size_t  count)
inline

Returns a span of the last count elements.

Parameters
countNumber of elements.
Returns
A new Span viewing the last elements.

◆ operator[]() [1/2]

template<typename T >
T & Span< T >::operator[] ( size_t  index)
inline

Returns a reference to the element at index without bounds checking.

Parameters
indexZero-based element index.
Returns
Reference to the element.

◆ operator[]() [2/2]

template<typename T >
const T & Span< T >::operator[] ( size_t  index) const
inline

Returns a reference to the element at index without bounds checking.

Parameters
indexZero-based element index.
Returns
Reference to the element.

◆ revBegin()

template<typename T >
RevIterator Span< T >::revBegin ( )
inlinenoexcept

Returns a mutable reverse iterator to the last element.

◆ revEnd()

template<typename T >
RevIterator Span< T >::revEnd ( )
inlinenoexcept

Returns a mutable reverse iterator to one before the first element.

◆ subspan()

template<typename T >
Span Span< T >::subspan ( size_t  offset,
size_t  count 
)
inline

Returns a sub-span starting at offset with count elements.

Parameters
offsetStarting element index.
countNumber of elements.
Returns
A new Span viewing the sub-range.

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