X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Fcontainer.h;h=39106cefd4779bf05b3cbfb165f3c4b8226d1c08;hp=f382a8ae66012652f3abe761474d108e1c38bb80;hb=17aea0b2d1bf5230c39981ba36e1f7ced56cecbc;hpb=94155cc1f3da766086f4367457be50b20a7ff436 diff --git a/ginac/container.h b/ginac/container.h index f382a8ae..39106cef 100644 --- a/ginac/container.h +++ b/ginac/container.h @@ -3,7 +3,7 @@ * Wrapper template for making GiNaC classes out of STL containers. */ /* - * GiNaC Copyright (C) 1999-2003 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2005 Johannes Gutenberg University Mainz, Germany * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,7 +17,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef __GINAC_CONTAINER_H__ @@ -28,6 +28,7 @@ #include #include #include +#include #include "ex.h" #include "print.h" @@ -66,6 +67,63 @@ template <> inline void container_storage::reserve(std::vector & v, size_t n) { v.reserve(n); } +/** Helper template to allow initialization of containers via an overloaded + * comma operator (idea stolen from Blitz++). */ +template +class container_init { +public: + container_init(STLT & s) : stlt(s) {} + + container_init operator,(const T & x) + { + stlt.push_back(x); + return container_init(stlt); + } + + // The following specializations produce much tighter code than the + // general case above + + container_init operator,(int x) + { + stlt.push_back(x); + return container_init(stlt); + } + + container_init operator,(unsigned int x) + { + stlt.push_back(x); + return container_init(stlt); + } + + container_init operator,(long x) + { + stlt.push_back(x); + return container_init(stlt); + } + + container_init operator,(unsigned long x) + { + stlt.push_back(x); + return container_init(stlt); + } + + container_init operator,(double x) + { + stlt.push_back(x); + return container_init(stlt); + } + + container_init operator,(const symbol & x) + { + stlt.push_back(T(x)); + return container_init(stlt); + } + +private: + container_init(); + STLT & stlt; +}; + /** Wrapper template for making GiNaC classes out of STL containers. */ template