2011-09-19 55 views
1

代码:在新的gcc中未实现,但在旧的实现?

#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: In function '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: instantiated from 'Retrun_T TupleFunctionCall(Retrun_T (*)(Args_T ...), std::tuple<_Elements ...>) [with Retrun_T = double, Args_T = {double, double}]'
prog.cpp:25:104: instantiated from here
prog.cpp:14:84: sorry, unimplemented: use of 'type_pack_expansion' in template
prog.cpp:14:84: error: call of overloaded '_TupleFunctionCall(double (*&)(double, double), std::tuple&, double&, double&)' is ambiguous prog.cpp:6:10: note: candidates are: 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: note: 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}]

为什么在老克++实现,但不是在新一?

+2

看起来这已经出现在的G ++一生几次。以下是一个更近的问题,并提供了一些可能的解决方法:http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48292 – Joe

+0

乔,你想把它变成答案,以便我们可以将它标记出来吗? – spraff

回答