【发布时间】:2021-09-26 04:39:08
【问题描述】:
假设我有一个template 函数:
template<typename T>
T produce_5_function() { return T(5); }
如何将整个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 >()();
但我希望能够使用原始函数模板来做到这一点:
template<??? F>
struct client_template {
int operator()() const { return F<int>(); }
};
int five = client_template< produce_5_function >()();
我怀疑答案是“你不能这样做”。
【问题讨论】:
标签: c++ templates c++11 function-templates