X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?a=blobdiff_plain;f=ginac%2Fcontainer.h;h=242395b62c2e2d215b09c325ca1bb93e76e63d6c;hb=c734f9bb6a1ce0aad913aa19a56542d84d86c60d;hp=4b6d0552550fc2784b707528b0b0867a167cf9f9;hpb=4aaa6006a9408999aa4fe336a14180035aa8c791;p=ginac.git diff --git a/ginac/container.h b/ginac/container.h index 4b6d0552..242395b6 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-2004 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 @@ -67,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