Tuesday, October 1, 2013

Aliasing in C++11

In C++11, we can use using keyword instead of typedef . E.g:
using UINT = unsigned int;
UINT num = 200;

Template aliasing is also possible in C++11. Which can be used to bind types. E.g:

template<typename C>
using element_type = typename C::value_type;

element_type<vector<int>> num = 10; // element_type will become int

One more observation here is that it is not (as in C++98) necessary to place a space between the two >'s. Another Example:
template<typename Value>
using String_map = Map<string,Value>
String_map<int> m; // m is a Map<str ing,int>