小编uni*_*ptr的帖子

可变模板专业化问题

我想要一个通用的方法来处理函数并最终调用它们所以我编写下面的代码问题是代码正在编译但是当我测试它时我得到了类的错误

错误的模板参数数量(1,应为0)auto al = action :: apply <5> :: value;

所以我知道我做错了什么,但我找不到它是什么.

template<typename T, typename enabled=void, typename ...P>
struct action{
    template<P... args>
    struct apply{ };
};

template<typename FN,typename ...P>
struct action<FN, typename std::enable_if< std::is_function<FN>::value >::type ,P...>{
    template<P... args>
    struct apply{ 
         static const  decltype( std::result_of<FN(P...)>::type ) value = FN( std::forward<P>(args)...);
    };
};


int test(int x)
{
    return x;
}

int main()
{
  auto al= action<decltype(test), int>::apply<5>::value;
  std::cout << "result :" << al <<std::endl;
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ templates variadic-templates c++11

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

标签 统计

c++ ×1

c++11 ×1

templates ×1

variadic-templates ×1