我们来屁股,我们有一个模板功能:
template<typename T1,typename T2,typename T3> T3 such_fun(T1 a,T2 b) { // do something... }
现在我们想用它作为另一个模板中的参数,例如像那样
template<typename T1,template<typename,typename,typename> some_function> void big_fun(T1 a) { // some code... a = some_function<T1,T1,T1>(a,a); // some code... }
可能吗?
我知道我可以使用具有define()运算符的struct.我只是好奇的功能.
编辑:
template<typename T1,T1 (*some_function)(T1,T1)> void big_fun(T1 a) { // some code... a = some_function(a,a); // some code... }
但仍然 – 我很好奇,如果可能没有在调用之前实现函数类型.例如 – 我可能想要使用各种类型的组合来调用传递的模板:
template<typename T1,typename> some_function> void big_fun(T1 a,T2 b) { // some code... a = some_function<T1,a); a = some_function<T1,T2,b); b = some_function<T2,T2>(b,a); // some code... }
解决方法
不,这是不可能的.从N3337的14.3.3:
A template-argument for a template template-parameter shall be the
name of a class template or an alias template,expressed as
id-expression . When the template-argument names a class template,
only primary class templates are considered when matching the template
template argument with the corresponding parameter; partial
specializations are not considered even if their parameter lists match
that of the template template parameter.
原文地址:https://www.jb51.cc/c/113211.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。