|
Re: Your C++ Wish List (Editorial)
|
Posted: Sep 28, 2004 4:58 AM
|
|
I like templates and use them frequently and the most libraries are based on them too, but what I miss is the possibility to define templates with an unknown number of parameters. The BOOST tuple class or signal/slot classes or many others use copy & paste (or the preprocessor) and they are all limited to a fixed maximal count of parameters (e.g. 3 or 5 or 10).
It would be nice, if C++ could itself construct templates with any number of parameters (as '...' in printf()).
extensions to C++:
- '...' in templates - '##' is the number of '...' parameters (N) - '#' iterates over all the parameters (1 - N)
examples:
template<class A, ...> class X { typedef # arg#_type;
X(A a, ...) { } };
template<class T, ...> f(const T& t, ...) { g(t, ...); }
template<typename F, typename T, ...> class result_of<F(...)> { static F f; static # t#;
public: typedef typeof(f(...)) type; };
template <...> struct group { # a#; group(...) : a#(#...) {} };
template <class Ch, class Tr, ...> inline BOOST_IO_STD basic_ostream<Ch, Tr>& operator << (BOOST_IO_STD basic_ostream<Ch, Tr>& os, const group<...>& x) { os << x.a#; return os; }
I know this is hard work for compiler vendors but this would replace many copy & paste code and fewer use of the preprocessor.
I would also appreciate, if the header guards (with "#ifdef") could be replaced by another command (e.g. "#pragma once" like some (but not all) vendors do - I know that this is another pp-command, but easier to use).
|
|