Gamedev Framework (gf) 1.2.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 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)
 Get an element at a given index. More...
 
constexpr const T & operator[] (std::size_t index) const
 Get an element at a given 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 Span< T > firstExcept () const noexcept
 Take a 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 Span< T > lastExcept () 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 ( )
inlineconstexpr

Default constructor.

Data is nullptr and size is 0.

◆ Span() [2/9]

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

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

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

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

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

Constructor from another static span.

Parameters
otherThe other span

Member Function Documentation

◆ begin() [1/2]

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

Take a 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 >
constexpr Span< T > gf::Span< T >::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

◆ getData() [1/2]

template<typename T >
constexpr const T * gf::Span< T >::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 >
constexpr T * gf::Span< T >::getData ( )
inlineconstexprnoexcept

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
inlineconstexprnoexcept

Get the number of elements.

Returns
The number of elements in the array

◆ isEmpty()

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

Check if the array is empty.

Returns
True if the array has no elements

◆ last() [1/2]

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

Take a 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 >
constexpr Span< T > gf::Span< T >::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 >
constexpr T & gf::Span< T >::operator[] ( std::size_t  index)
inlineconstexpr

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
inlineconstexpr

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 >
template<std::size_t B, std::size_t E>
constexpr StaticSpan< T, E - B > gf::Span< T >::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 >
constexpr Span< T > gf::Span< T >::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