template<typename T>
Array2d class

Generic, resizable, 2D array class.

Derived classes

template<typename T>
class Image
An image with a generic pixel type.

Constructors, destructors, conversion operators

Array2d()
empty array, 0 by 0 elements
Array2d(int size_x, int size_y, const T& value = T(0.))
size_x by size_y 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(const Vec2i& size)
Resize to (size.x) x (size.y)
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
Vec2i m_size
size along both directions

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 -> Vec2i
size along both directions
auto length() const -> int
total number of elements