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

A static span. More...

#include <gf/Span.h>

Public Member Functions

constexpr StaticSpan () noexcept
 Default constructor. More...
 
constexpr StaticSpan (std::nullptr_t) noexcept
 Null constructor. More...
 
constexpr StaticSpan (T *data, std::size_t size) noexcept
 Constructor from a pointer and a size. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
constexpr StaticSpan (U(&data)[N]) noexcept
 Constructor from a static array. More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
constexpr StaticSpan (std::array< U, N > &array) noexcept
 Constructor from a std::array More...
 
template<typename U , typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
constexpr StaticSpan (StaticSpan< U, N > other) noexcept
 Constructor from another 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) noexcept
 Get an element at a given index. More...
 
constexpr const Toperator[] (std::size_t index) const noexcept
 Get an element at a given index. More...
 
template<std::size_t I>
constexpr Tget () noexcept
 Get an element at a constant index. More...
 
template<std::size_t I>
constexpr const Tget () const noexcept
 Get an element at a constant 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 StaticSpan< T, Size - CfirstExcept () const noexcept
 Take a constant 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 StaticSpan< T, Size - ClastExcept () const noexcept
 Take a constant span on the last objects. More...
 

Static Public Attributes

static constexpr std::size_t Size = N
 The size of the span. More...
 

Detailed Description

template<typename T, std::size_t N>
class gf::StaticSpan< T, N >

A static span.

A span is a non-owning reference to a contiguous sequence of objects. A static span knows the number of objects at compile-time.

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

See also
gf::Span

Constructor & Destructor Documentation

◆ StaticSpan() [1/6]

template<typename T, std::size_t N>
constexpr gf::StaticSpan< T, N >::StaticSpan ( )
inlinenoexcept

Default constructor.

Data is nullptr.

◆ StaticSpan() [2/6]

template<typename T, std::size_t N>
constexpr gf::StaticSpan< T, N >::StaticSpan ( std::nullptr_t  )
inlinenoexcept

Null constructor.

Data is nullptr.

◆ StaticSpan() [3/6]

template<typename T, std::size_t N>
constexpr gf::StaticSpan< T, N >::StaticSpan ( T data,
std::size_t  size 
)
inlinenoexcept

Constructor from a pointer and a size.

The size must match the constant size of the span.

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

◆ StaticSpan() [4/6]

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

Constructor from a static array.

The size must match the constant size of the span.

Parameters
dataThe static array

◆ StaticSpan() [5/6]

template<typename T, std::size_t N>
template<typename U , typename = std::enable_if_t<std::is_convertible<U(*)[], T(*)[]>::value>>
constexpr gf::StaticSpan< T, N >::StaticSpan ( std::array< U, N > &  array)
inlinenoexcept

Constructor from a std::array

The size must match the constant size of the span.

Parameters
arrayThe array of elements

◆ StaticSpan() [6/6]

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

Constructor from another span.

Parameters
otherThe other span

Member Function Documentation

◆ begin() [1/2]

template<typename T, std::size_t N>
constexpr T* gf::StaticSpan< T, N >::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, std::size_t N>
constexpr const T* gf::StaticSpan< T, N >::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, std::size_t N>
constexpr T* gf::StaticSpan< T, N >::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, std::size_t N>
constexpr const T* gf::StaticSpan< T, N >::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, std::size_t N>
constexpr Span<T> gf::StaticSpan< T, N >::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, std::size_t N>
template<std::size_t C>
constexpr StaticSpan<T, C> gf::StaticSpan< T, N >::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, std::size_t N>
constexpr Span<T> gf::StaticSpan< T, N >::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, std::size_t N>
template<std::size_t C>
constexpr StaticSpan<T, Size - C> gf::StaticSpan< T, N >::firstExcept ( ) const
inlinenoexcept

Take a constant span on the first objects.

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

◆ get() [1/2]

template<typename T, std::size_t N>
template<std::size_t I>
constexpr T& gf::StaticSpan< T, N >::get ( )
inlinenoexcept

Get an element at a constant index.

Returns
The element at the given index

◆ get() [2/2]

template<typename T, std::size_t N>
template<std::size_t I>
constexpr const T& gf::StaticSpan< T, N >::get ( ) const
inlinenoexcept

Get an element at a constant index.

Returns
The element at the given index

◆ getData() [1/2]

template<typename T, std::size_t N>
constexpr T* gf::StaticSpan< T, N >::getData ( )
inlinenoexcept

Get a pointer to the elements.

Returns
A pointer to the first element in the array

◆ getData() [2/2]

template<typename T, std::size_t N>
constexpr const T* gf::StaticSpan< T, N >::getData ( ) const
inlinenoexcept

Get a pointer to the elements.

Returns
A pointer to the first element in the array

◆ getSize()

template<typename T, std::size_t N>
constexpr std::size_t gf::StaticSpan< T, N >::getSize ( ) const
inlinenoexcept

Get the number of elements.

Returns
The number of elements in the array

◆ isEmpty()

template<typename T, std::size_t N>
constexpr bool gf::StaticSpan< T, N >::isEmpty ( ) const
inlinenoexcept

Check if the array is empty.

Returns
True if the array has no elements

◆ last() [1/2]

template<typename T, std::size_t N>
constexpr Span<T> gf::StaticSpan< T, N >::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, std::size_t N>
template<std::size_t C>
constexpr StaticSpan<T, C> gf::StaticSpan< T, N >::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, std::size_t N>
constexpr Span<T> gf::StaticSpan< T, N >::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, std::size_t N>
template<std::size_t C>
constexpr StaticSpan<T, Size - C> gf::StaticSpan< T, N >::lastExcept ( ) const
inlinenoexcept

Take a constant 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, std::size_t N>
constexpr T& gf::StaticSpan< T, N >::operator[] ( std::size_t  index)
inlinenoexcept

Get an element at a given index.

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

◆ operator[]() [2/2]

template<typename T, std::size_t N>
constexpr const T& gf::StaticSpan< T, N >::operator[] ( std::size_t  index) const
inlinenoexcept

Get an element at a given index.

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

◆ slice() [1/2]

template<typename T, std::size_t N>
constexpr Span<T> gf::StaticSpan< T, N >::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, std::size_t N>
template<std::size_t B, std::size_t E>
constexpr StaticSpan<T, E - B> gf::StaticSpan< T, N >::slice ( ) const
inlinenoexcept

Take a constant sub-span.

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

Member Data Documentation

◆ Size

template<typename T, std::size_t N>
constexpr std::size_t gf::StaticSpan< T, N >::Size = N
static

The size of the span.