nothrow nothrow - 1 year ago 86
C++ Question

Typedef (alias) of an generic class

is it possible in C++ to create an alias of template class (without specifying parameters)?

typedef std::map myOwnMap;

doesn't work.

And if not, is there any good reason?

Answer Source

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 :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download