 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Michael Pryhodko Guest
|
Posted: Wed Jan 12, 2005 7:35 am Post subject: templatedef |
|
|
What do you think about this 'template typedef' proposal (I tried to
discuss it in comp.lang.c++.moderated):
----------------------< begin >-----------------------
// some templates
template<class T> class type {};
template<class T, class U> class ptr {};
// convenient shortcut
templatedef<class T, class U> ptr< T, type TmplAlias;
Rules are pretty the same as for 'typedef':
- just like typedef does not create new type 'templatedef' does not
create new template -- it is only convenient shortcut to given
'template-name + params' entity.
- it has similar syntax
- templatedef for template functions could be built to look similar to
typedef for usual functions.
I'd like to outline some advantages of this 'templatedef':
a) you can create fine-looking and human-readable complex template
specializations, e.g.:
template<class U> class TmplAlias<U, U> {};
is equivalent to:
template<class U> class ptr<U, type {};
b) you can change number of template parameters in order to pass
template as template template argument, e.g.:
template<class U, class T> class foo;
template<template class B;
templatedef<class U> foo< U*, foo2 TmplAlias;
B<TmplAlias> foo_var; // cannot be done without templatedef
c) consequently you can get around that nasty 'default template
parameters' problem, e.g.:
template<template class B;
template<class T, class U = A> class Foo;
templatedef<class T> Foo<T> Foo_without_def_params;
// now Foo_without_def_params can be used whenever
// template with one parameter required, e.g.:
B<Foo_without_def_params> foo_var;
----------------------< end >-----------------------
I already read n1489 (and currently I am "reading through" the
collection of these notes and proposals). But here is my thoughts about
n1489:
1. I think that:
templatedef<class T> foo<T, U> t_alias;
looks more 'natural' than
template<class T> using t_alias = foo<T, U>;
because it more closely reflects 'typedef' syntax with respect to
templates (IMHO).
2. I disagree that (partial) template specialization using t-aliases
should be banned:
a) it looks natural to me
b) since t-alias is just substitution to more complex t-name it should
not create any problem in any existing template specialization logic
c) I was not convinced by the reasons described in n1489 )
3. well... that paper introduces extensions to 'using' keyword more
than introducing 'template typedef' :)
Bye.
Sincerely yours, Michael.
P.S. Just want to influence C++ evolution :)
---
[ 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 ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|