Gamedev Framework (gf)  0.19.0
A C++17 framework for 2D games
Public Member Functions | List of all members
gf::Span< T > Class Template Reference

A span. More...

#include <gf/Span.h>

Public Member Functions

constexpr Span ()
 Default constructor. More...
 
constexpr Span (std::nullptr_t)
 Null constructor. More...
 
constexpr Span (T *data, std::size_t size)
 Constructor from a pointer and a size. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
 Span (std::vector< U > &values)
 Constructor from a std::vector More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value && std::is_const<T>::value>>
 Span (const std::vector< U > &values)
 Constructor from a std::vector More...
 
template<typename U , std::size_t N, typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
 Span (std::array< U, N > &values)
 Constructor from a std::array More...
 
template<typename U , std::size_t N, typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
constexpr Span (U(&data)[N])
 Constructor from a static array. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
constexpr Span (Span< U > other)
 Constructor from another span. More...
 
template<typename U , std::size_t N, typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
constexpr Span (StaticSpan< U, N > other)
 Constructor from another static span. More...
 
constexpr TgetData () noexcept
 Get a pointer to the elements. More...
 
constexpr const TgetData () const noexcept
 Get a pointer to the elements. More...
 
constexpr std::size_t getSize () const noexcept
 Get the number of elements. More...
 
constexpr bool isEmpty () const noexcept
 Check if the array is empty. More...
 
constexpr Tbegin () noexcept
 Get an iterator to the first element. More...
 
constexpr Tend () noexcept
 Get an iterator past the last element. More...
 
constexpr const Tbegin () const noexcept
 Get an iterator to the first element. More...
 
constexpr const Tend () const noexcept
 Get an iterator past the last element. More...
 
constexpr Toperator[] (std::size_t index)
 Get an element at a given index. More...
 
constexpr const Toperator[] (std::size_t index) const
 Get an element at a given index. More...
 
constexpr Span< Tslice (std::size_t b, std::size_t e) const noexcept
 Take a sub-span. More...
 
template<std::size_t B, std::size_t E>
constexpr StaticSpan< T, E - Bslice () const noexcept
 Take a constant sub-span. More...
 
constexpr Span< Tfirst (std::size_t count) const noexcept
 Take a span on the first objects. More...
 
template<std::size_t C>
constexpr StaticSpan< T, Cfirst () const noexcept
 Take a constant span on the first objects. More...
 
constexpr Span< Tlast (std::size_t count) const noexcept
 Take a span on the last objects. More...
 
template<std::size_t C>
constexpr StaticSpan< T, Clast () const noexcept
 Take a constant span on the last objects. More...
 
constexpr Span< TfirstExcept (std::size_t count) const noexcept
 Take a span on the first objects. More...
 
template<std::size_t C>
constexpr Span< TfirstExcept () const noexcept
 Take a span on the first objects. More...
 
constexpr Span< TlastExcept (std::size_t count) const noexcept
 Take a span on the last objects. More...
 
template<std::size_t C>
constexpr Span< TlastExcept () const noexcept
 Take a span on the last objects. More...
 

Detailed Description

template<typename T>
class gf::Span< T >

A span.

A span is a non-owning reference to a contiguous sequence of objects.

This class stores a pointer to some data and its size. It can be built from various inputs: std::vector, static array, pointer and size.

See also
gf::StaticSpan

Constructor & Destructor Documentation

◆ Span() [1/9]

template<typename T>
constexpr gf::Span< T >::Span ( )
inline

Default constructor.

Data is nullptr and size is 0.

◆ Span() [2/9]

template<typename T>
constexpr gf::Span< T >::Span ( std::nullptr_t  )
inline

Null constructor.

Data is nullptr and size is 0.

◆ Span() [3/9]

template<typename T>
constexpr gf::Span< T >::Span ( T data,
std::size_t  size 
)
inline

Constructor from a pointer and a size.

Parameters
dataA pointer to the elements in the array
sizeThe number of elements in the array

◆ Span() [4/9]

template<typename T>
template<typename U , typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
gf::Span< T >::Span ( std::vector< U > &  values)
inline

Constructor from a std::vector

Parameters
valuesThe vector of elements

◆ Span() [5/9]

template<typename T>
template<typename U , typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value && std::is_const<T>::value>>
gf::Span< T >::Span ( const std::vector< U > &  values)
inline

Constructor from a std::vector

Parameters
valuesThe vector of elements

◆ Span() [6/9]

template<typename T>
template<typename U , std::size_t N, typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
gf::Span< T >::Span ( std::array< U, N > &  values)
inline

Constructor from a std::array

Parameters
valuesThe array of elements

◆ Span() [7/9]

template<typename T>
template<typename U , std::size_t N, typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
constexpr gf::Span< T >::Span ( U(&)  data[N])
inline

Constructor from a static array.

The size is computed at compile-time.

Parameters
dataThe static array

◆ Span() [8/9]

template<typename T>
template<typename U , typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
constexpr gf::Span< T >::Span ( Span< U other)
inline

Constructor from another span.

Parameters
otherThe other span

◆ Span() [9/9]

template<typename T>
template<typename U , std::size_t N, typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
constexpr gf::Span< T >::Span ( StaticSpan< U, N other)
inline

Constructor from another static span.

Parameters
otherThe other span

Member Function Documentation

◆ begin() [1/2]

template<typename T>
constexpr T* gf::Span< T >::begin ( )
inlinenoexcept

Get an iterator to the first element.

Returns
A pointer to the first element
See also
end()

◆ begin() [2/2]

template<typename T>
constexpr const T* gf::Span< T >::begin ( ) const
inlinenoexcept

Get an iterator to the first element.

Returns
A pointer to the first element
See also
end()

◆ end() [1/2]

template<typename T>
constexpr T* gf::Span< T >::end ( )
inlinenoexcept

Get an iterator past the last element.

Returns
A pointer past the last element
See also
begin()

◆ end() [2/2]

template<typename T>
constexpr const T* gf::Span< T >::end ( ) const
inlinenoexcept

Get an iterator past the last element.

Returns
A pointer past the last element
See also
begin()

◆ first() [1/2]

template<typename T>
constexpr Span<T> gf::Span< T >::first ( std::size_t  count) const
inlinenoexcept

Take a span on the first objects.

Parameters
countThe number of objects in the new span
Returns
The sub-span

◆ first() [2/2]

template<typename T>
template<std::size_t C>
constexpr StaticSpan<T, C> gf::Span< T >::first ( ) const
inlinenoexcept

Take a constant span on the first objects.

Template Parameters
CThe number of objects in the new span
Returns
The sub-span

◆ firstExcept() [1/2]

template<typename T>
constexpr Span<T> gf::Span< T >::firstExcept ( std::size_t  count) const
inlinenoexcept

Take a span on the first objects.

Parameters
countThe number of objects not in the new span
Returns
The sub-span

◆ firstExcept() [2/2]

template<typename T>
template<std::size_t C>
constexpr Span<T> gf::Span< T >::firstExcept ( ) const
inlinenoexcept

Take a span on the first objects.

Template Parameters
CThe number of objects not in the new span
Returns
The sub-span

◆ getData() [1/2]

template<typename T>
constexpr T* gf::Span< T >::getData ( )
inlinenoexcept

Get a pointer to the elements.

Returns
A pointer to the first element in the array

◆ getData() [2/2]

template<typename T>
constexpr const T* gf::Span< T >::getData ( ) const
inlinenoexcept

Get a pointer to the elements.

Returns
A pointer to the first element in the array

◆ getSize()

template<typename T>
constexpr std::size_t gf::Span< T >::getSize ( ) const
inlinenoexcept

Get the number of elements.

Returns
The number of elements in the array

◆ isEmpty()

template<typename T>
constexpr bool gf::Span< T >::isEmpty ( ) const
inlinenoexcept

Check if the array is empty.

Returns
True if the array has no elements

◆ last() [1/2]

template<typename T>
constexpr Span<T> gf::Span< T >::last ( std::size_t  count) const
inlinenoexcept

Take a span on the last objects.

Parameters
countThe number of objects in the new span
Returns
The sub-span

◆ last() [2/2]

template<typename T>
template<std::size_t C>
constexpr StaticSpan<T, C> gf::Span< T >::last ( ) const
inlinenoexcept

Take a constant span on the last objects.

Template Parameters
CThe number of objects in the new span
Returns
The sub-span

◆ lastExcept() [1/2]

template<typename T>
constexpr Span<T> gf::Span< T >::lastExcept ( std::size_t  count) const
inlinenoexcept

Take a span on the last objects.

Parameters
countThe number of objects not in the new span
Returns
The sub-span

◆ lastExcept() [2/2]

template<typename T>
template<std::size_t C>
constexpr Span<T> gf::Span< T >::lastExcept ( ) const
inlinenoexcept

Take a span on the last objects.

Template Parameters
CThe number of objects not in the new span
Returns
The sub-span

◆ operator[]() [1/2]

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

Get an element at a given index.

No verification is done on the index.

Parameters
indexThe index of the element
Returns
The element at the given index

◆ operator[]() [2/2]

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

Get an element at a given index.

No verification is done on the index.

Parameters
indexThe index of the element
Returns
The element at the given index

◆ slice() [1/2]

template<typename T>
constexpr Span<T> gf::Span< T >::slice ( std::size_t  b,
std::size_t  e 
) const
inlinenoexcept

Take a sub-span.

Parameters
bThe begin index
eThe end index, past the last
Returns
A sub-span

◆ slice() [2/2]

template<typename T>
template<std::size_t B, std::size_t E>
constexpr StaticSpan<T, E - B> gf::Span< T >::slice ( ) const
inlinenoexcept

Take a constant sub-span.

Template Parameters
BThe begin index
EThe end index, past the last
Returns
A sub-span