1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#ifndef MATRIX_H_INCLUDED
#define MATRIX_H_INCLUDED
#include <vector>
#include <cassert>
#include <iostream>
#include <fstream>
template<class T>
class Matrix
{
public:
Matrix(std::size_t width, std::size_t height, T const& t = T{}) :
w(width),
h(height),
datas(w*h, t) {}
Matrix(Matrix const& m) = default;
Matrix& operator=(Matrix const& m) = default;
T const& operator()(std::size_t x, std::size_t y) const
{
assert(x < w && y < h && "Out of Bound");
return datas[y*w+x];
}
T& operator()(std::size_t x, std::size_t y)
{
assert(x < w && y < h && "Out of Bound");
return datas[y*w+x];
}
std::size_t width() const{ return w; }
std::size_t height() const{ return h; }
private:
std::size_t w;
std::size_t h;
std::vector<T> datas;
};
#endif // MATRIX_H_INCLUDED |