コード:新しい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}]
なぜそれが古いグラムで++ではなく、新たなに実装されています1?
が見えます。いくつかの回避策があります:http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48292 – Joe
ジョー、それを答えに変えて、マークすることができますか? – spraff