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

A constant reference to an array and its size. More...

#include <gf/ArrayRef.h>

Public Member Functions

constexpr ArrayRef ()
 Default constructor. More...
 
constexpr ArrayRef (std::nullptr_t)
 Null constructor. More...
 
constexpr ArrayRef (const T *data, std::size_t size)
 Constructor from a pointer and a size. More...
 
 ArrayRef (const std::vector< T > &values)
 Constructor from a std::vector More...
 
template<std::size_t N>
 ArrayRef (const std::array< T, N > &values)
 Constructor from a std::array More...
 
template<std::size_t N>
constexpr ArrayRef (const T(&data)[N])
 Constructor from a static array. More...
 
 ArrayRef (std::initializer_list< T > values)
 Constructor from an initializer list. 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 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 const Toperator[] (std::size_t index) const
 Get an element at a given index. More...
 

Detailed Description

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

A constant reference to an array and its size.

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::BufferRef, gf::StringRef

Constructor & Destructor Documentation

◆ ArrayRef() [1/7]

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

Default constructor.

Data is nullptr and size is 0.

◆ ArrayRef() [2/7]

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

Null constructor.

Data is nullptr and size is 0.

◆ ArrayRef() [3/7]

template<typename T>
constexpr gf::ArrayRef< T >::ArrayRef ( const 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

◆ ArrayRef() [4/7]

template<typename T>
gf::ArrayRef< T >::ArrayRef ( const std::vector< T > &  values)
inline

Constructor from a std::vector

Parameters
valuesThe vector of elements

◆ ArrayRef() [5/7]

template<typename T>
template<std::size_t N>
gf::ArrayRef< T >::ArrayRef ( const std::array< T, N > &  values)
inline

Constructor from a std::array

Parameters
valuesThe array of elements

◆ ArrayRef() [6/7]

template<typename T>
template<std::size_t N>
constexpr gf::ArrayRef< T >::ArrayRef ( const T(&)  data[N])
inline

Constructor from a static array.

The size is computed at compile-time.

Parameters
dataThe static array

◆ ArrayRef() [7/7]

template<typename T>
gf::ArrayRef< T >::ArrayRef ( std::initializer_list< T values)
inline

Constructor from an initializer list.

Parameters
valuesThe list of elements

Member Function Documentation

◆ begin()

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

Get an iterator to the first element.

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

◆ end()

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

Get an iterator past the last element.

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

◆ getData()

template<typename T>
constexpr const T* gf::ArrayRef< 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::ArrayRef< T >::getSize ( ) const
inlinenoexcept

Get the number of elements.

Returns
The number of elements in the array

◆ isEmpty()

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

Check if the array is empty.

Returns
True if the array has no elements

◆ operator[]()

template<typename T>
constexpr const T& gf::ArrayRef< 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