代码:
#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&lt; _Tail ...&gt;,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&lt; _Elements ...&gt;)实例化[使用Retrun_T = double,Args_T = {double,double} ]“
prog.cpp:25:104:从这里实例化 prog.cpp:14:84:抱歉,未实现:在模板中使用'type_pack_expansion'
prog.cpp:14:84:错误:调用重载的'_TupleFunctionCall(double(*&amp;)(double,double),std :: tuple&amp;,double&amp;,double&amp;)'是不明确的 prog.cpp:6:10:注意:候选者是:Retrun_T _TupleFunctionCall(Retrun_T(*)(Args_T ...),std :: tuple&lt; _Tail ...&gt;,Args_T ...)[with int N = 2 ,Retrun_T = double,Args_T = {double,double}]
prog.cpp:12:10:注:Retrun_T _TupleFunctionCall(Retrun_T(*)(Args_T ...),标准::元组&LT; _Tail ...&gt;中Interm_Args_T ......)[用INT N = 2,Retrun_T = double,Args_T = {double,double},Interm_Args_T = {double,double}]
为什么它是用旧的g ++实现的,而不是用新的++实现的?
答案 0 :(得分:0)