C++11 可变参数模板函数 -- 错误在哪里?
C++11 Variadic Template Function -- where's the error?
下面的代码给出了msvc++ 2012 CTP(支持c++ 11)和Intel c++ XE 13.0的编译错误:
template <typename F, typename... Args>
void apply(F f, std::tuple<Args...>& args) {
// doesn't do much yet
}
bool f1(char c) {
return c == 'c';
}
int main(int argc, char* argv[]) {
auto t = std::make_tuple('c');
apply(f1, t);
return 0;
}
VS2012错误是:
error C2243: 'type cast' :
conversion from 'std::tuple<char,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil> *'
to 'std::tuple<std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil,std::_Nil> &' exists,
but is inaccessible
Intel c++ XE 13.0错误:
error : no instance of function template "apply" matches the argument list
我错过了什么?这里真的有错误吗,还是我有两个不好的编译器?
UPDATE:当我在两个编译器上使用boost::tuple而不是std::tuple时,结果相同(或类似)。
附录:感谢所有评论中的交叉检查。我已经向这两家公司发送了bug报告。
这很可能是标准库实现中的VC11错误。尽管CTP支持可变模板,但据我所知,标准库并没有为了使用它们而重写,而是采用了一些机制来模拟可变模板。
相关文章:
- C++泛型类错误,问题出在哪里?
- 我的重复检查代码中的错误究竟在哪里?
- 这个 absl::StrCat 错误在哪里发生,在 Abseil 或 MSVC 中?
- 错误在哪里,为什么这个程序是错误的?
- 致命错误idk在哪里?
- G :内部编译器错误:分割故障(程序CC1PLUS) - 我在哪里开始
- 我在计算 4 个值的方差时的错误在哪里
- 我的调试器说我有一个隔离错误错误,但无法告诉我在哪里,在非常特殊的情况下发生
- 我在Qt信号和插槽问题上的错误在哪里?
- c++双自由或损坏(fasttop)--不确定错误在哪里
- 我的代码中的错误在哪里
- C++外部程序集:我的代码中的错误在哪里
- 此代码中的分段错误在哪里
- 随机生成器测试.错误在哪里
- 树程序中的错误在哪里
- 我的C++代码中的错误在哪里
- 错误在哪里?显示字符串C++Vignere密码
- 我是使用getline的新手,错误在哪里?
- 这个函数请求用户通过循环输入文件名的错误在哪里?
- C++11 可变参数模板函数 -- 错误在哪里?