codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
#include <iostream> namespace a { class matrix { public: explicit matrix(size_t h, size_t w) : height(h), width(w), data(new float[h*w]) {} struct proxy { explicit proxy(float *data) : data(data){} float& operator[](size_t y) { return data[y]; } float *data; }; proxy operator[](size_t x) { return proxy(data+x*height); } private: size_t height, width; float *data; }; } namespace b { class matrix { public: explicit matrix(size_t h, size_t w) : height(h), width(w), data(new float[h*w]) {} float& operator()(size_t x, size_t y) { return data[x*height+y]; } private: size_t height, width; float *data; }; } namespace c { class matrix { public: explicit matrix(size_t h, size_t w) : height(h), width(w), data(new float[w*h]) {} struct proxy { explicit proxy(matrix *m, size_t x) : m(m), x(x) {} float& operator[](size_t y) { return m->unchecked_at(x,y); } matrix *m; float x; }; proxy operator[](size_t x) { return proxy(this, x); } float& unchecked_at(int x, int y) { return data[x*height+y]; } private: size_t height, width; float *data; }; } float access_dilkad_matrix(a::matrix a, int x, int y) { return a[x][y]; } float access_parashift_matrix(b::matrix b, int x, int y) { return b(x, y); } float access_volkard_matrix(c::matrix c, int x, int y) { return c[x][y]; }
Private
[
?
]
Run code
Submit