[英]VS2015 Variadic templates bug?
template<typename T0, typename T1, typename ...ArgN>
bool is_any_test(T0 arg0, T1 arg1, ArgN... argn...)
{
return arg0 == arg1 || is_any_test<T0, ArgN...>(arg0, argn...);
};
template<typename T0, typename T1>
bool is_any_test(T0 arg0, T1 arg1)
{
return arg0 == arg1;
};
int wmain(int /*argc*/, const wchar_t* /*argv[]*/)
{
is_any_test(3,4);
return 0;
};
(can run it right here http://webcompiler.cloudapp.net/ ) (可以在这里运行http://webcompiler.cloudapp.net/ )
On VS2015 this results in 在VS2015上,这会导致
C2668 ambiguous call to overloaded function
On VS2013 this worked fine. 在VS2013上,这很好用。 Is this a bug or am I missing something? 这是一个错误还是我错过了什么? Is there any workaroung? 有没有workaroung? (changing all the occurancies to plain ifs - is not an option) (将所有的行为改为普通的ifs - 不是一种选择)
I've modified your code to working example (not tested 100%..) 我已将您的代码修改为工作示例(未经过100%测试..)
template <class T>
bool is_any_test_impl(T t) {
return false;
}
template<class T1,class T2,class... Args>
bool is_any_test_impl(T1 t1, T2 t2, Args&&... args) {
return t1 == t2 || is_any_test_impl(std::forward<T1>(t1),std::forward<Args>(args)...);
}
template<class... Args>
bool is_any_test(Args&&... args)
{
return is_any_test_impl(std::forward<Args>(args)...);
};
/*
auto b = is_any_test(1, 2, 3, 4, 5); //false
auto b1 = is_any_test(1, 2, 3, 4, 5, 1); //true
*/
Typo. 错字。 See comments for more detail... 有关详细信息,请参阅评论
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.