template <class T> class matrix;
template <class T>
class proxy_matrix
{
public:
proxy_matrix(matrix<T> *m, int i) : mptr(m), row(i) { }
T& operator[](int j) { return mptr->at(row,j); }
const T& operator[](int j) const { return mptr->at(row,j); }
private:
matrix<T> *mptr;
int row;
};
template <class T>
class matrix
{
public:
proxy_matrix<T> operator[](int i)
{
return proxy_matrix<T>(this,i);
}
T& at(int i, int j) { return v[i*x+j]; }
const T& at(int i, int j) const { return v[i*x+j]; }
T& operator()(int i, int j) { return v[i*x+j]; }
const T& operator()(int i, int j) const { return v[i*x+j]; }
private:
int x;
int y;
T *v;
};