Не реализовано в новом gcc, но реализовано в старом? - PullRequest
1 голос
/ 20 сентября 2011

код:

#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 ...) [с 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 ...>) [с 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 ...) [с 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 ...) [с int N = 2, Retrun_T = double , Args_T = {double, double}, Interm_Args_T = {double, double}]

Почему это реализовано в старом g ++, а не в новом?

1 Ответ

0 голосов
/ 25 октября 2011
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...