X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?a=blobdiff_plain;f=ginac%2Fcontainer.h;h=2459b364ffb0d36c70004f530cdc1cd147dd1751;hb=79e49016f3a732fe1758bc3efd10f0727862017c;hp=c6a72e276d9226d76c06fe492a9879aa664248e3;hpb=f5e84af31b20c7f732bee375bacc152e7fb01e56;p=ginac.git diff --git a/ginac/container.h b/ginac/container.h index c6a72e27..2459b364 100644 --- a/ginac/container.h +++ b/ginac/container.h @@ -28,6 +28,7 @@ #include #include #include +#include #include "ex.h" #include "print.h" @@ -66,6 +67,64 @@ 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