我有以下简单的例子:
// Function we are interested in using.
template<template<typename> class A>
void B(A<int>&) { }
template<typename C, typename D>
class E { };
// "Adapter" to have only one template argument for E.
template<typename F>
using G = E<F, int>;
int main()
{
G<int> h;
B(h); // fails!
// B<G>(h); // does not fail!
}
在此示例中,我们使用模板别名来获得正确数量的模板参数来调用函数 C()。当然,这是从导致此问题的实际情况中提取的,因此解决方法不是这里的解决方案(也不是我正在寻找的)。
gcc 给出:
test2.cpp: In function ‘int main()’:
test2.cpp:14:6: error: no matching function for call to ‘B(G<int>&)’
B(h);
^
test2.cpp:2:6: note: candidate: template<template<class> class A> void B(A<int>&)
void B(A<int>&) { }
^
test2.cpp:2:6: note: template argument deduction/substitution failed:
test2.cpp:14:6: error: wrong number of template arguments (2, should be 1)
B(h);
^
test2.cpp:1:35: note: provided for ‘template<class> class A’
template<template<typename> class A>
根据标准,这是来自 gcc 的正确输出吗?对我来说,在这种情况下,该语言似乎应该允许对模板别名进行适当的类型推断。