Typedef (alias) of an generic class
In C++98 and C++03 typedef
may only be used on a complete type:
typedef std::map<int,int> IntToIntMap;
With C++0x there is a new shiny syntax to replace typedef
:
using IntToIntMap = std::map<int,int>;
which also supports template
aliasing:
template <
typename Key,
typename Value,
typename Comparator = std::less<Key>,
typename Allocator = std::allocator< std::pair<Key,Value> >
>
using myOwnMap = std::map<Key,Value,Comparator,Allocator>;
Here you go :)
Template typedefs are not supported in the C++03 standard. There are workarounds, however:
template<typename T>
struct MyOwnMap {
typedef std::map<std::string, T> Type;
};
MyOwnMap<int>::Type map;
This feature will be introduced in C++0x, called template alias. It will be looking like this:
template<typename Key, typename Value>
using MyMap = std::map<Key, Value>