C ++自动用于类型和非类型模板 [英] c++ auto for type and nontype templates

查看:66
本文介绍了C ++自动用于类型和非类型模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在c ++ 17中, template< auto> 允许使用任意类型参数声明模板.部分受问题的启发,扩展 template< auto> 可以同时捕获类型和非类型模板参数,并且还可以使用可变参数版本.

In c++17 template <auto> allows to declare templates with arbitrary type parameters. Partially inspired by this question, it would be useful to have an extension of template <auto> that captures both type and nontype template parameters, and also allows for a variadic version of it.

在下一个c ++ 20版本中是否有计划进行此类扩展?使用 X 任何类型或非类型模板参数的 template< auto ... X> 这样的语法是否存在一些基本问题?

Are there plans for such an extension in the next c++20 release? Is there some fundamental problem in having a syntax like template<auto... X>, with X any type or nontype template parameter?

推荐答案

在下一个c ++ 20版本中是否有计划进行此类扩展?

Are there plans for such an extension in the next c++20 release?

否.

使用 X 任何类型或非类型模板参数的 template< auto ... X> 这样的语法是否存在一些基本问题?

Is there some fundamental problem in having a syntax like template<auto... X>, with X any type or nontype template parameter?

这将是该语言中的一个全新概念-在同一个地方使用 类型值表示名称.因此,它会带来各种其他问题-可能还会有其他语言功能来检查 X 是否是一种类型.

It would be a totally new concept in the language - having a name refer to either a type or a value in the same place. So it'd come with all sorts of additional questions - and probably additional language features to check if X is a type or not.

不能的语法可能是 template< auto ... X>struct Y {}; ,因为该语法已经具有含义并表示一堆值,并且 Y< int> {} 格式错误.

The syntax likely cannot be template <auto... X> struct Y { }; since that syntax already has meaning and means a bunch of values and Y<int>{} is ill-formed.

尽管在某些地方肯定会有用.一项提案只需要解决这些问题.

There are definitely places where such a thing would be useful though. A proposal would just have to address these issues.

这篇关于C ++自动用于类型和非类型模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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