C ++-模板模板参数可以是变量还是函数? [英] C++ - Can a template template parameter be of a variable or function?

查看:69
本文介绍了C ++-模板模板参数可以是变量还是函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我仍在尝试完全理解模板.我认为它们是特殊类型.

I'm still trying to fully understand templates. I see them as special types.

最近,我正在阅读有关类和模板模板参数的信息. 我想知道是否有可能具有功能或变量而不只是类的模板模板参数?像这样:

Recently I was reading about template template parameters of classes and I'm wondering if it it is possible to have a template template parameter of function or variable and not only of class? Something like this:

template<typename T> void func(T); //template of function 'func'

template<int a> double var = a; //template of variable 'var'

template<template<typename> void templ_param() = func, //parameter template of function

template<int> double templ_param_0 = var //parameter template of variable

> void func1();

如果不是,为什么,还有什么替代方案?

If not why and what is the alternative?

推荐答案

我想知道是否可以有一个功能为模板的模板参数

I'm wondering if it it is possible to have a template template parameter of function

不,您不能.您的示例代码段不起作用.

No, you cannot. Your example code snippet won't work.

template <template <typename T>> void templ_param() = func,

模板模板参数必须是类模板或别名模板.

A template template parameter must be a class template or an alias template.

根据C ++标准:

14.3.3模板范本

1模板 template-parameter template-argument 应该是类模板或别名模板的名称,表示为 id-expression .

1 A template-argument for a template template-parameter shall be the name of a class template or an alias template, expressed as id-expression.

这篇关于C ++-模板模板参数可以是变量还是函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆