Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/151.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 我在接受未打包的可变模板参数的函数上使用延迟返回类型时遇到问题_C++_Templates - Fatal编程技术网

C++ 我在接受未打包的可变模板参数的函数上使用延迟返回类型时遇到问题

C++ 我在接受未打包的可变模板参数的函数上使用延迟返回类型时遇到问题,c++,templates,C++,Templates,我在接受未打包的可变模板参数的函数上使用延迟返回类型时遇到问题。这不会在11月CTP Visual Studio中编译 template <typename Function, typename ...Args> auto invoke ( Function f, Args... args) -> decltype(f(args...)) { return f(args...); } int foo(int x, const char* y = "Hello

我在接受未打包的可变模板参数的函数上使用延迟返回类型时遇到问题。这不会在11月CTP Visual Studio中编译

template <typename Function, typename ...Args>
auto invoke ( Function f, Args... args)
    -> decltype(f(args...))
{

    return f(args...);
}

int foo(int x, const char* y = "Hello") {
    cout << x << " : " << y << endl;

    return x;
};

int _tmain(int argc, TCHAR* argv[]) {

    auto v = invoke(&foo, 10, "Hello There");
    cout << v << endl;

    return 0;
}
模板
自动调用(函数f、参数…参数)
->decltype(f(args…)
{
返回f(args…);
}
int foo(int x,const char*y=“你好”){

cout以防有人需要。下面的解决方法对我很有效

template <typename F> struct freturn_type;
template <typename R, typename... A>
struct freturn_type<R (*)(A...)>
{
    typedef R type;
};


template <typename Function, typename ...Args>
typename freturn_type<Function>::type invoke ( Function f, Args... args)
    //-> decltype(f(args...))
{
    return f(args...);
};
模板结构类型;
模板
结构类型
{
typedef-R型;
};
模板
typename\u type::type invoke(函数f,Args…Args)
//->decltype(f(args…)
{
返回f(args…);
};

以防有人需要。以下解决方法对我很有效

template <typename F> struct freturn_type;
template <typename R, typename... A>
struct freturn_type<R (*)(A...)>
{
    typedef R type;
};


template <typename Function, typename ...Args>
typename freturn_type<Function>::type invoke ( Function f, Args... args)
    //-> decltype(f(args...))
{
    return f(args...);
};
模板结构类型;
模板
结构类型
{
typedef-R型;
};
模板
typename\u type::type invoke(函数f,Args…Args)
//->decltype(f(args…)
{
返回f(args…);
};

您尝试过使用三个点吗?
decltype(f(args…)
另外,通常
invoke()
类型的函数倾向于完美地转发参数:
auto invoke(function f,args&…args)->decltype(f(std::forward(args)…)
错误C2893:未能专门化函数模板的未知类型etl::invoke(函数,Args…)与std::forward的错误相同。VS的2012 CTP是出了名的错误。不要相信它而不回头看。只要转到VS13,它应该是一个更好的体验。您尝试过使用三个点吗?
decltype(f(Args…)
另外,通常是
invoke()
倾向于完美地转发参数:
auto invoke(function f,Args&&…Args)->decltype(f(std::forward(Args)…)
错误C2893:未能专门化函数模板的未知类型etl::invoke(function,Args…)“std::forward也有同样的错误。VS的2012 CTP是出了名的bug。不要不回头看就相信它。只需转到VS13,它应该是一个更好的体验。”。