【问题标题】:Unimplemented in new gcc but implemented in old one?在新 gcc 中未实现但在旧 gcc 中实现?
【发布时间】:2011-09-19 23:57:15
【问题描述】:

代码:

#include <tuple>
#include <cmath>
#include <iostream>

template <int N, typename Retrun_T, typename... Args_T>
Retrun_T _TupleFunctionCall(Retrun_T (*function)(Args_T... Args), std::tuple<Args_T...> Args, Args_T... RealArgs)
{
    return function(RealArgs...);
}

template <int N, typename Retrun_T, typename... Args_T, typename... Interm_Args_T>
Retrun_T _TupleFunctionCall(Retrun_T (*function)(Args_T... Args), std::tuple<Args_T...> Args, Interm_Args_T... RealArgs)
{
    return _TupleFunctionCall<N + 1>(function, Args, RealArgs..., std::get<N>(Args));
}

template <typename Retrun_T, typename... Args_T>
Retrun_T TupleFunctionCall(Retrun_T (*function)(Args_T... Args), std::tuple<Args_T...> Args)
{
    return _TupleFunctionCall<1>(function, Args, std::get<0>(Args));
}

int main(int argc, char *argv[])
{
    std::cout << TupleFunctionCall<double, double, double>(&std::pow, std::tuple<double, double>(10, 2)) << std::endl;
}

在 g++ 4.4.2 中编译并运行良好,但在 g++ 4.5.2 中产生错误:

prog.cpp: 在函数 'Retrun_T _TupleFunctionCall(Retrun_T (*)(Args_T ...), std::tuple<_tail ...>, Interm_Args_T ...) [with int N = 1, Retrun_T = double , Args_T = {double, double}, Interm_Args_T = {double}]':
prog.cpp:20:67: 从 'Retrun_T TupleFunctionCall(Retrun_T (*)(Args_T ...), std::tuple<_elements ...>) [with Retrun_T = double, Args_T = {double, double}] 实例化'
prog.cpp:25:104: 从这里实例化
prog.cpp:14:84: 抱歉,未实现:在模板中使用 'type_pack_expansion'
prog.cpp:14:84: 错误: 重载 '_TupleFunctionCall(double (*&)(double, double), std::tuple&, double&, double&)' 的调用不明确 prog.cpp:6:10:注意:候选人是:Retrun_T _TupleFunctionCall(Retrun_T (*)(Args_T ...), std::tuple<_tail ...>, Args_T ...) [with int N = 2, Retrun_T = double, Args_T = {double, double}]
prog.cpp:12:10: 注意: Retrun_T _TupleFunctionCall(Retrun_T (*)(Args_T ...), std::tuple<_tail ...>, Interm_Args_T ...) [with int N = 2, Retrun_T = double , Args_T = {double, double}, Interm_Args_T = {double, double}]

为什么在旧的 g++ 中实现了,而在新的 g++ 中没有实现?

【问题讨论】:

  • 看起来这在 G++ 的生命周期中已经出现过几次。这是最近的一个,有一些可能的解决方法:gcc.gnu.org/bugzilla/show_bug.cgi?id=48292
  • 乔,你想把它变成一个答案,以便我们标记它吗?

标签: gcc c++11


【解决方案1】:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-08
    • 2010-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多