Topic: Template-typedefs
Author: Ralf Stoffels <stoffels@faho.rwth-aachen.de>
Date: 1996/12/08 Raw View
Why do have no "template-typedefs" in C++ ?
If you want to shorten long typenames you usually write i.e.
typedef A< B<int>, C<D<int> > > E;
Why is not possible to shorten templates like this:
template <typename T>
typedef A< B<T>, C<D<T> > > E<T>;
or
template <typename T>
typedef vector<T>::const_iterator iter<T>;
Is there a different way to express this ?
Ralf
---
[ 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 ]
Author: fjh@mundook.cs.mu.OZ.AU (Fergus Henderson)
Date: 1996/12/09 Raw View
Ralf Stoffels <stoffels@faho.rwth-aachen.de> writes:
>Why do have no "template-typedefs" in C++ ?
I don't know. I certainly think C++ would be a better language
if it did have template typedefs.
>Is there a different way to express this ?
Yes, you can use a typedef inside a template class.
However, that is a pretty ugly work-around, IMHO.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: Chelly Green <chelly@eden.com>
Date: 1996/12/09 Raw View
Ralf Stoffels wrote:
>
> Why do have no "template-typedefs" in C++ ?
This is discussed in The Design and Evolution of C++, on page 457.
Bjarne talks about ways of achieving this using inheritance. He says
"The extension is technically trivial, but I'm not sure how wise it
would be to introduce yet another renaming feature." I assume he is
speaking of a lack of experience with the construct, since there isn't
an implementation to try. I bet GCC will (or already does) support this
feature.
Information about the book (which I recommend):
http://www.research.att.com/~bs/dne.html
> If you want to shorten long typenames you usually write i.e.
> typedef A< B<int>, C<D<int> > > E;
>
> Why is not possible to shorten templates like this:
> template <typename T>
> typedef A< B<T>, C<D<T> > > E<T>;
>
> or
> template <typename T>
> typedef vector<T>::const_iterator iter<T>;
>
> Is there a different way to express this ?
Derivation:
template<typename T>
struct iter : vector<T>::const_iterator {
// forwarding ctors, and assignment ops, etc. that aren't
// inherited into this scope
};
Of course, you'll have to write the forwarding functions mentioned.
--
Chelly Green | chelly@eden.com | C++ - http://www.eden.com/~chelly
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]