【发布时间】:2018-08-07 10:07:01
【问题描述】:
我有一个模板模板方法,当使用不在命名空间中的模板调用它时,它可以正常工作。但是,当使用命名空间中的模板调用它时,我会收到一个 clang 错误。 MSVC 和 gcc 编译没有问题,但只有当我将标准设置为 C++17 时。
这是一个最小的例子
#include <vector>
template<template<typename> typename Template>
Template<int> foo() {
return {};
}
template <typename T>
using my_vector = std::vector<T>;
int main()
{
foo<my_vector>(); // compiles
foo<std::vector>(); // does not compile in clang or without C++17
}
没有C++17的gcc错误是:
<source>:14:5: error: no matching function for call to 'foo'
clang 错误是:
<source>:14:22: error: no matching function for call to 'foo<template<class _Tp, class _Alloc> class std::vector>()'
<source>:4:15: note: candidate template ignored: invalid explicitly-specified argument for template parameter 'Template'
C++17 中发生了哪些变化以允许这样做,它是 clang 产生错误的错误吗?
【问题讨论】:
-
恕我直言,命名模板类型参数
Template是一个值得商榷的选择:) -
P0522R0。请参阅clang.llvm.org/cxx_status.html#p0522 了解 clang 禁用此功能的原因。
-
@lubgr 是的,我知道,我只是想在这个例子中它可能清楚我的意思:)
标签: c++ templates c++17 clang++