假设我有一个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>()();
我怀疑答案是“你不可以做这个”。
有一个根本原因模板的模板参数不能是功能模板?这可能会在未来得到解决吗? – Olumide 2018-02-08 16:46:53
@Olumide:可能是因为它有很多额外的复杂性并且很容易解决(请参阅mfontanini的回答)。部分专业化也是如此,这比模板模板参数使用得更多。 – 2018-02-26 17:57:24