小编Dan*_*ahy的帖子

为什么GCC会产生一个奇怪的错误,并在明确指定模板参数时尝试调用错误的方法?

我有一个submitAsync接受模板化std::function参数的函数:

template <typename Ret, typename... Args>                                                                                                                                                     
Future<Ret> submitAsync(const function<Ret (Args...)> &func, Args&&... args);
Run Code Online (Sandbox Code Playgroud)

但是,传递lambda时隐式模板参数推导不起作用(类似于此处的问题,因此我必须创建一个更通用的函数,将该函数作为模板参数接受,然后将其传递给原始函数:

template <typename Func, typename... Args>
auto submitAsync(Func &&func, Args&&... args) -> // Line 82, where the strange error occurs
    Future<
        typename enable_if<
            is_convertible<
                Func, function<decltype(func(args...)) (Args...) >
            >::value ,  decltype(func(args...))
        >::type
    > {
    typedef decltype(func(args...)) ReturnType;
    return submitAsync<ReturnType, Args...>(function<ReturnType (Args...)>(func), forward<Args>(args)...);
}
Run Code Online (Sandbox Code Playgroud)

这与Clang编译良好,但GCC返回以下错误:

src/Scheduler.hpp: In substitution of ‘template<class Func, class ... Args> Future<typename std::enable_if<std::is_convertible<Func, std::function<decltype (func(MCServer::Scheduler::startThread::args ...))(Args ...)> >::value, decltype …
Run Code Online (Sandbox Code Playgroud)

c++ gcc templates c++11

8
推荐指数
1
解决办法
1372
查看次数

标签 统计

c++ ×1

c++11 ×1

gcc ×1

templates ×1