相关疑难解决方法(0)

如何在模板参数列表中传递模板函数

假设我有一个template功能:

template<typename T>
T produce_5_function() { return T(5); }
Run Code Online (Sandbox Code Playgroud)

我怎么能将这整个传递template给另一个template

如果produce_5_function是仿函数,那就没有问题:

template<typename T>
struct produce_5_functor {
  T operator()() const { return T(5); }
};
template<template<typename T>class F>
struct client_template {
  int operator()() const { return F<int>()(); }
};
int five = client_template< produce_5_functor >()();
Run Code Online (Sandbox Code Playgroud)

但我希望能够使用原始函数模板执行此操作:

template<??? F>
struct client_template {
  int operator()() const { return F<int>(); }
};
int five = client_template< produce_5_function >()();
Run Code Online (Sandbox Code Playgroud)

我怀疑答案是"你不能这样做".

c++ templates function-templates c++11

27
推荐指数
2
解决办法
7212
查看次数

标签 统计

c++ ×1

c++11 ×1

function-templates ×1

templates ×1