Utility class to add [][] access. More...
#include <MatrixSquareBracketsAccess.h>
Classes | |
class | Const_row |
Small utility class which just contains a pointer to the T and the row number. More... | |
class | Row |
Small utility class which just contains a pointer to the T and the row number. More... | |
Public Member Functions | |
Row | operator[] (I i) |
access element (with [][] syntax) More... | |
Const_row | operator[] (I i) const |
access element (with [][] syntax) More... | |
Utility class to add [][] access.
T | The type of the matrix class. |
C | The type of the returned value. |
I | The type of the first index (default unsigned). |
J | The type of the second index (default unsigned). |
It implements the trick described in C++ FAQ 13.12 to allow [][] access to matrix-like classes, based on the (,) syntax, thus translating [i][j] into (i,j). In practice, one only needs to implement the (,) syntax and to inherit from MatrixSquareBracketsAccess. The first template parameter (T) should be the class itself, the second (C) is the type of the returned value, and the third (I) and fourth (J) are the types of the two indexes (unsigned by default). As everything is inlined, no overhead is expected.
class MyMatrixClass: public MatrixSquareBracketsAccess<MyMatrixClass,double> { double data[16]; public: double & operator ()(unsigned i,unsigned j){ return data[4*i+j]; } const double & operator ()(unsigned i,unsigned j)const{ return data[4*i+j]; } }; int main(){ MyMatrixClass m; m[0][1]=3.0; return 0; }
Definition at line 69 of file MatrixSquareBracketsAccess.h.
MatrixSquareBracketsAccess< T, C, I, J >::Row PLMD::MatrixSquareBracketsAccess< T, C, I, J >::operator[] | ( | I | i | ) |
access element (with [][] syntax)
Definition at line 118 of file MatrixSquareBracketsAccess.h.
MatrixSquareBracketsAccess< T, C, I, J >::Const_row PLMD::MatrixSquareBracketsAccess< T, C, I, J >::operator[] | ( | I | i | ) | const |
access element (with [][] syntax)
Definition at line 123 of file MatrixSquareBracketsAccess.h.
Hosted by GitHub
![]() |
![]() |