2012-10-10 CPlusPlus11

Template-ized typedefs and template Aliases

With C++11 we can define a typedef as a template using the keyword using. Suppose you have a type with the template type parameter T and the template int parameter size. Now typedefs can't be templates but with the new using syntax the type can be defined like this:

template<typename T, int size>
using TheType = array<T, size>;

Achieving the same result as typedef. Now we have a type, TheType?, that is a template type.

It does not end there. We can further partially bind a template using the same syntax. So if we would like to define a new type based on TheType? but with the size bound to 10 we would do like this:

template <typename T>
using SizeTen = TheType<T, 10>;