我如何将现有模板类部分分为新类型

How can I partially specialize a existing template class into a new type?

本文关键字:新类型 类型 类部      更新时间:2023-10-16

-----重要:这不是部分模板专业化的解决方案,而是我在不知道的情况下寻找类型的别名。对不起,混乱------

我想做的

我想专业地将BOOST :: UNOREREDED_MULTIMAP本质上只需要存储的数据,因此将密钥永久性化为boost :: uuids :: uuid。

当前尝试

template<class t>
boost::unordered_multimap<boost::uuids::uuid, t, boost::hash<boost::uuids::uuid>> unorderedUUIDMultMap;'
    Here is the usage:
        unorderedUUIDMultMap<int> uuidMultMap; //Should create a mutlimap storing ints.

这是错误:

main.cpp|24|error: expected ';' before 'uuidMultMap'|

我还尝试在模板之前使用" typedef",但这也没有奏效。

我如何正确执行此简单的快捷方式?

您想要的不是部分专业化,而是模板类型别名:

template <typename T> using my_mmap = boost::unordered_multimap<boost::uuids::uuid, T, boost::hash<boost::uuids::uuid>>;