gpt4 book ai didi

C++11 Variadic 模板函数——错误在哪里?

转载 作者:搜寻专家 更新时间:2023-10-31 01:11:48 26 4
gpt4 key购买 nike

以下代码在 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

我错过了什么?这里真的有错误,还是我只有两个糟糕的编译器?

更新:当我在两个编译器上使用 boost::tuple 而不是 std::tuple 时,结果相同(或相似)。

附录:感谢评论中的所有交叉检查。我已将错误报告发送给这两家优秀的公司。

最佳答案

这可能是标准库实现中的 VC11 错误。虽然 CTP 支持可变参数模板,但据我所知,标准库并没有被重写以使用它们,而是采用了一些机制来模拟可变参数模板。这可能是您问题的根源。

关于C++11 Variadic 模板函数——错误在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14387924/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com