template<typename T>
Array2d class

Generic, resizable, 2D array class.

Constructors, destructors, conversion operators

Array2d()
empty array, 0 by 0 elements
Array2d(int sizeX, int sizeY, const T& value = T(0.))
sizeX by sizeY elements
Array2d(const Array2d&)
copy constructor
~Array2d()
destructor

Public functions

auto operator=(const Array2d&) -> Array2d&
assignment operator
auto index_1d(int x, int y) const -> int
Convert the 2d index into a linear index.
auto index_2d(int i) const -> std::pair<int, int>
Convert the 1d index into a 2d index.
void resize(int sizeX, int sizeY)
Resize to sizeX x sizeY
void reset(const T& value = T(0))
Set all elements to value
void operator=(const T&)
Set all elements to value

Protected variables

std::vector<T> m_data
the data
int m_sizeX
size of first dimension
int m_sizeY
size of second dimension

Element access

auto at(int x, int y) -> T&
bounds-checked 2d access
auto at(int x, int y) const -> const T&
bounds-checked 2d access
auto operator()(int x, int y) -> T&
unchecked 2d access
auto operator()(int x, int y) const -> const T&
unchecked 2d access
auto at(int i) -> T&
bounds-checked linear access
auto at(int i) const -> const T&
bounds-checked linear access
auto operator()(int i) -> T&
unchecked linear access
auto operator()(int i) const -> const T&
unchecked linear access
auto row(int y) const -> const T*
pointer to y-th row

Dimension sizes

auto width() const -> int
size of first dimension
auto height() const -> int
size of second dimension
auto size() const -> int
total number of elements
auto sizeX() const -> int
size of first dimension
auto sizeY() const -> int
size of first dimension