Gamedev Framework (gf)  0.3.0
A C++11 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 (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>
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
 Get a pointer to the elements. More...
 
constexpr std::size_t getSize () const
 Get the number of elements. More...
 
constexpr const Tbegin () const
 Get an iterator to the first element. More...
 
constexpr const Tend () const
 Get an iterator past the last element. 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
StringRef

Constructor & Destructor Documentation

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

Default constructor.

Data is nullptr and size is 0.

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
template<typename T >
gf::ArrayRef< T >::ArrayRef ( const std::vector< T > &  values)
inline

Constructor from a std::vector

Parameters
valuesThe vector of elements
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
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

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

Get an iterator to the first element.

Returns
A pointer to the first element
See also
end()
template<typename T >
constexpr const T* gf::ArrayRef< T >::end ( ) const
inline

Get an iterator past the last element.

Returns
A pointer past the last element
See also
begin()
template<typename T >
constexpr const T* gf::ArrayRef< T >::getData ( ) const
inline

Get a pointer to the elements.

Returns
A pointer to the first element in the array
template<typename T >
constexpr std::size_t gf::ArrayRef< T >::getSize ( ) const
inline

Get the number of elements.

Returns
The number of elements in the array