Given your additional information about the templates, we can now respond.
A use case is when you want to specialize in a type of template. One typical example:
template <typename T> struct nonconst { typedef T t; }; template <typename T> struct nonconst<T const> { typedef T t; };
This effectively removes the const qualifier from any type:
nonconst<int>::tx; nonconst<int const>::ty; assert(typeid(x) == typeid(int)); assert(typeid(y) == typeid(int));
There are many similar use cases, for example. add (or remove) a pointer qualifier from a type, provide default and specialization values for certain types, etc.
However, pay attention to the different shell of type names! Equal types in typedef TT are illegal C ++. [I stand fixed: §7.1.3.2] In addition, the de facto naming standard (cemented by its use in Boost libraries) is to invoke a type name with an alias type , for example:
typedef T type;
Konrad Rudolph
source share