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?
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With