Gamedev Framework (gf) 1.2.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 T * getData () noexcept
 Get a pointer to the elements. More...
 
constexpr const T * getData () 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 T * begin () noexcept
 Get an iterator to the first element. More...
 
constexpr T * end () noexcept
 Get an iterator past the last element. More...
 
constexpr const T * begin () const noexcept
 Get an iterator to the first element. More...
 
constexpr const T * end () const noexcept
 Get an iterator past the last element. More...
 
constexpr T & operator[] (std::size_t index) noexcept
 Get an element at a given index. More...
 
constexpr const T & operator[] (std::size_t index) const noexcept
 Get an element at a given index. More...
 
template<std::size_t I>
constexpr T & get () noexcept
 Get an element at a constant index. More...
 
template<std::size_t I>
constexpr const T & get () const noexcept
 Get an element at a constant index. More...
 
constexpr Span< T > slice (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 - B > slice () const noexcept
 Take a constant sub-span. More...
 
constexpr Span< T > first (std::size_t count) const noexcept
 Take a span on the first objects. More...
 
template<std::size_t C>
constexpr StaticSpan< T, C > first () const noexcept
 Take a constant span on the first objects. More...
 
constexpr Span< T > last (std::size_t count) const noexcept
 Take a span on the last objects. More...
 
template<std::size_t C>
constexpr StaticSpan< T, C > last () const noexcept
 Take a constant span on the last objects. More...
 
constexpr Span< T > firstExcept (std::size_t count) const noexcept
 Take a span on the first objects. More...
 
template<std::size_t C>
constexpr StaticSpan< T, Size - C > firstExcept () const noexcept
 Take a constant span on the first objects. More...
 
constexpr Span< T > lastExcept (std::size_t count) const noexcept
 Take a span on the last objects. More...
 
template<std::size_t C>
constexpr StaticSpan< T, Size - C > lastExcept () 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 ( )
inlineconstexprnoexcept

Default constructor.

Data is nullptr.

◆ StaticSpan() [2/6]

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

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 
)
inlineconstexprnoexcept

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])
inlineconstexprnoexcept

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)
inlineconstexprnoexcept

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)
inlineconstexprnoexcept

Constructor from another span.

Parameters
otherThe other span

Member Function Documentation

◆ begin() [1/2]

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

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 T * gf::StaticSpan< T, N >::begin ( )
inlineconstexprnoexcept

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 const T * gf::StaticSpan< T, N >::end ( ) const
inlineconstexprnoexcept

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 T * gf::StaticSpan< T, N >::end ( )
inlineconstexprnoexcept

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>
template<std::size_t C>
constexpr StaticSpan< T, C > gf::StaticSpan< T, N >::first ( ) const
inlineconstexprnoexcept

Take a constant span on the first objects.

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

◆ first() [2/2]

template<typename T , std::size_t N>
constexpr Span< T > gf::StaticSpan< T, N >::first ( std::size_t  count) const
inlineconstexprnoexcept

Take a span on the first objects.

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

◆ firstExcept() [1/2]

template<typename T , std::size_t N>
template<std::size_t C>
constexpr StaticSpan< T, Size - C > gf::StaticSpan< T, N >::firstExcept ( ) const
inlineconstexprnoexcept

Take a constant span on the first objects.

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

◆ firstExcept() [2/2]

template<typename T , std::size_t N>
constexpr Span< T > gf::StaticSpan< T, N >::firstExcept ( std::size_t  count) const
inlineconstexprnoexcept

Take a span on the first objects.

Parameters
countThe 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 const T & gf::StaticSpan< T, N >::get ( ) const
inlineconstexprnoexcept

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 T & gf::StaticSpan< T, N >::get ( )
inlineconstexprnoexcept

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 const T * gf::StaticSpan< T, N >::getData ( ) const
inlineconstexprnoexcept

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 T * gf::StaticSpan< T, N >::getData ( )
inlineconstexprnoexcept

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
inlineconstexprnoexcept

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
inlineconstexprnoexcept

Check if the array is empty.

Returns
True if the array has no elements

◆ last() [1/2]

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

Take a constant span on the last objects.

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

◆ last() [2/2]

template<typename T , std::size_t N>
constexpr Span< T > gf::StaticSpan< T, N >::last ( std::size_t  count) const
inlineconstexprnoexcept

Take a span on the last objects.

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

◆ lastExcept() [1/2]

template<typename T , std::size_t N>
template<std::size_t C>
constexpr StaticSpan< T, Size - C > gf::StaticSpan< T, N >::lastExcept ( ) const
inlineconstexprnoexcept

Take a constant span on the last objects.

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

◆ lastExcept() [2/2]

template<typename T , std::size_t N>
constexpr Span< T > gf::StaticSpan< T, N >::lastExcept ( std::size_t  count) const
inlineconstexprnoexcept

Take a span on the last objects.

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

◆ operator[]() [1/2]

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

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 T & gf::StaticSpan< T, N >::operator[] ( std::size_t  index)
inlineconstexprnoexcept

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

Take a constant sub-span.

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

◆ slice() [2/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
inlineconstexprnoexcept

Take a sub-span.

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
staticconstexpr

The size of the span.