Typedef a template class without specifying the template parameters

我的未来我决定 提交于 2019-11-29 23:00:00

The way I've seen this done is to wrap the typedef in a template-struct:

template<typename KeyType, typename MappedType>
struct myMap
{
#ifdef _TR1
    typedef std::tr1::unordered_map<KeyType, MappedType> type;
#else
    typedef std::map<KeyType, MappedType> type;
#endif
};

Then in your code you invoke it like so:

myMap<key, value>::type myMapInstance;

It may be a little more verbose than what you want, but I believe it meets the need given the current state of C++.

You have to use full types for typedefs.

Use a #define macro instead.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!