如果 Argument 是具有特定第一个模板参数(任意模板化)的某个模板,我想要一个特定的函数来进行计算。
考虑这些类
template<class S> struct A { };
template<class S> struct B { };
template<class S> struct C { };
template<class S, class U = B<S>> struct D { };
我试图实现我的目标
template<template<class ... X> class Y, class Z>
inline void foo(Y<A<Z>> const &av) { std::cout << "2\n"; }
问题:MSVS 2013 无法推断Y
.
int main()
{
foo(C<A<int>>()); // prints 2 as intended
foo(D<A<int>>()); // does NOT compile in VS 2013
return 0;
}
错误的原因(根据 MSVS)是:
模板参数
const Y<A<Z>> &
不能从D<A<int>, B<S>>
with推导出来S=A<int>
。
我的目标是编写一个重载/特化来处理任何给定的类型Y
,其中Y::value_type
/的第一个模板参数Y
可以A<T>
是要保留 foo 签名的任何位置:void foo (Y const &);
这是 MSVS 中的错误(因为foo(D<A<int>>());
实际上使用 g++ 打印 2)还是我遗漏了什么?
PS:如果你在乎的话,圣诞快乐...