1

The code:

#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;
}

compiles and runs fine in g++ 4.4.2, but produces an error in 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}]

Why is it implemented in old g++ but not in new one?

Daniel
  • 30,896
  • 18
  • 85
  • 139
  • 2
    Looks like this has come up a few times in G++'s lifetime. Here's a more recent one, with some possible workarounds: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48292 – Joe Sep 20 '11 at 00:11
  • Joe, do you want to turn that into an answer so we can mark it off? – spraff Sep 28 '11 at 08:37

1 Answers1

0

The question seems related to variadic template, you may refer to the link: GCC error with variadic templates: "Sorry, unimplemented: cannot expand 'Identifier...' into a fixed-length argument list"

Community
  • 1
  • 1
Yun Huang
  • 4,256
  • 7
  • 27
  • 36