X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fmatrix.h;h=fc6a80bf4e6b3127eb701809792d948fdb694525;hp=36e7284650986db7cc58052806a1733cc771aed2;hb=ffad02322624ab79fdad1a23a3aa83cd67376151;hpb=ff3d5ccc8add5bfe76502479768c89d768df8384 diff --git a/ginac/matrix.h b/ginac/matrix.h index 36e72846..fc6a80bf 100644 --- a/ginac/matrix.h +++ b/ginac/matrix.h @@ -30,6 +30,65 @@ namespace GiNaC { + +/** Helper template to allow initialization of matrices via an overloaded + * comma operator (idea stolen from Blitz++). */ +template +class matrix_init { +public: + matrix_init(It i) : iter(i) {} + + matrix_init operator,(const T & x) + { + *iter = x; + return matrix_init(++iter); + } + + // The following specializations produce much tighter code than the + // general case above + + matrix_init operator,(int x) + { + *iter = T(x); + return matrix_init(++iter); + } + + matrix_init operator,(unsigned int x) + { + *iter = T(x); + return matrix_init(++iter); + } + + matrix_init operator,(long x) + { + *iter = T(x); + return matrix_init(++iter); + } + + matrix_init operator,(unsigned long x) + { + *iter = T(x); + return matrix_init(++iter); + } + + matrix_init operator,(double x) + { + *iter = T(x); + return matrix_init(++iter); + } + + matrix_init operator,(const symbol & x) + { + *iter = T(x); + return matrix_init(++iter); + } + +private: + matrix_init(); + It iter; +}; + + /** Symbolic matrices. */ class matrix : public basic { @@ -40,6 +99,14 @@ public: matrix(unsigned r, unsigned c); matrix(unsigned r, unsigned c, const exvector & m2); matrix(unsigned r, unsigned c, const lst & l); + + // First step of initialization of matrix with a comma-separated seqeuence + // of expressions. Subsequent steps are handled by matrix_init<>::operator,(). + matrix_init operator=(const ex & x) + { + m[0] = x; + return matrix_init(++m.begin()); + } // functions overriding virtual functions from base classes public: