Topic: further extension of templates
Author: tross@hookup.net (Andrew Trossman)
Date: 1996/05/05 Raw View
Using a component from STL as an example, I think templates should be
extended to include some sort of elipsis. Consider STL's function
pointer adapter components:
template <class Arg, class Result>>
class pointer_to_unary_function : public unary_function<Arg, Result> {
template <class Arg, class Result>>
pointer_to_unary_function<Arg, Result> ptr_fun(Result (*x)(Arg)) {
template <class Arg1, class Arg2, class Result>>
class pointer_to_binary_function : public binary_function<Arg1, Arg2,
Result>
template <class Arg1, class Arg2, class Result>>
pointer_to_binary_function<Arg1, Arg2, Result> ptr_fun(Result
(*x)(Arg1, Arg2)) ;{
Note that the latter two templates are 'templated' on the first two.
If something like elipsis were allowed, we could cut the above source
code in half.
Certainly any syntax I could think of would be pretty ugly to say the
least, but then again, how ugly is it to cut and paste code all over
the place? What if we want to parametrize functions taking three
parameters?
In my own work I have found other similar cases that could take
advantage of template elipsis. In some cases I've just done as STL
has, in others I've use pre-processing to generate lots of very
similar code. I can see how elipsis could satisfy coding
requirements, but I'm not sure on the 'real' role of templates.
Should templates simply replace macro expansion in general? In a
sence, what I've done, using a separate pre-processor, is the same as
macros, except that the standard pre-processor isn't powerfull enough.
I guess my question is, how generic should generic programming be?
Certainly the less source I write, the fewer bugs I will write,
Anyways, just some thoughts
}
Andrew Trossman
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]