Can non-type template parameters in c++17 be decltype(auto)?

半世苍凉 提交于 2019-11-30 04:41:35

This is standard. First, for a non-type template parameter:

[temp.param/4]

A non-type template-parameter shall have one of the following (optionally cv-qualified) types:

  • ...
  • a type that contains a placeholder type.

Where placeholder types have the following specified:

[dcl.spec.auto/1]

The auto and decltype(auto) type-specifiers are used to designate a placeholder type that will be replaced later by deduction from an initializer. The auto type-specifier is also used to introduce a function type having a trailing-return-type or to signify that a lambda is a generic lambda ([expr.prim.lambda.closure]). The auto type-specifier is also used to introduce a structured binding declaration.

[dcl.spec.auto/5]

A placeholder type can also be used in the type-specifier-seq in the new-type-id or type-id of a new-expression and as a decl-specifier of the parameter-declaration's decl-specifier-seq in a template-parameter.

Since the bullet above says "placeholder type", and such a type can be designated either with auto or decltype(auto), both compilers are correct.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!