From: Vesa Karvonen (vesa.karvonen_at_[hidden])
Date: 2001-06-25 14:42:30
on 6/25/01 12:21 AM, Jens Maurer at Jens.Maurer_at_[hidden] wrote:
> David Abrahams wrote:
>> I have often heard it claimed that anything you can do with template
>> parameters, you can also do without them, but better. I am not familiar
>> the arguments, so I can't evaluate their validity.
> The arguments concerning template-template parameters I heard concerned
> template parameters only. Here, we're dealing with deduced
> parameters for functions. Note that any "work-arounds" in this area is
> to prevent template argument deduction.
hmn... Admittedly, I just spotted this, and haven't followed the original
thread - perhaps I should, because quaternions have a number of important
applications in computer graphics and animation.
Anyway, I'm interested in seeing plausible uses of template template
parameters. I think that this subject might be more appropriate for a C++
newsgroup, except that I'm mainly interested in seeing actual use of template
template parameters in existing libraries.
At least in template metaprogramming, template template parameters seem to
have limited use and member templates seem much more powerful. The only truly
plausible "use" I know of, is that of adapting a metafunction into a
"metafunction object" (is there a better name for this concept?):
< template<class> class fun
< class T
struct code : fun<T>
Metafunction objects, which rely on member templates make it possible to:
- bind parameters (and curry):
< class fun_obj
, class p1
< class p0
struct code : fun_obj::template code<p0,p1>
- return a metafunction object or store it in a type data structure.
These techniques are quite powerful. For instance, I'm using lists that
contain metafunction objects in a parser/compiler for a list based
configuration DSL. This way it is possible to move more and more metacode into
metaprogramming libraries rather than embedding them into component libraries.
One of the problems with the C++ template mechanism, which is a pure
functional language, is that it doesn't support currying. In other words, the
following code is not C++:
template<class p0, class p1>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk