【发布时间】:2016-07-11 19:45:12
【问题描述】:
在以下示例中,我想使用模板函数 f 获取一个 stl 容器(列表或 unordered_set)。我知道 stl 容器会包含整数。
我尝试使用部分模板模板专业化,但它不起作用。
如何实现我想要的?
上面的代码显然不能编译。
#include <list>
#include <unordered_set>
template <typename T, template C<T>>
C<T> f()
{
C<T> d;
d.insert(1);
return d;
}
int main()
{
auto l = f<int, std::list<int>>();
auto s = f<int, std::unordered_set>();
return 0;
}
谢谢。
【问题讨论】: