Topic: [Q] parametrized typedef


Author: "Gabor Greif" <gabor@datawatch.de>
Date: 1997/12/16
Raw View
Has ever the question popped up to be able to parametrize typedef?

A small example (not proposed standard syntax!)

template <class T, class U>
struct Two
{
 //...
};

template <class U>
typedef Two<int, U> One; // One<U> would be a shortcut for Two<int, U>

This construction should satisfy the side-condition
typeid(Two<int, U>) == typeid(One<U>)
for every type U.

Something similar can be established with

template <class U>
struct One : Two<int, U> { };

but then the side-condition looses validity.

Clearly


template <class U, class T = int>
struct Two
{
 //...
};


satisfies typeid(Two<U, int>) == typeid(Two<U>)

, but is not really flexible since default template args can only be at the
right side.
It is also a kludge.

Typedefs can be used to abbreviate types or alias them, how about
templatized typedef to abbreviate or alias parametrized types?

My question is whether such a construct has been proposed for the standard.
I am also interested in elegant solutions to work around this "omission".
For me it is very important, that the above side-condition is valid.

Thanks,

 Gabor
---
[ 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
]