Rokiのチラ裏

学生による学習のログ

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

stackoverflow.com

template <decltype(auto)> // Is this legal by standard?
struct X {};

結論:
合法である。

n4659 17.1 Template parameters [temp.param]/paragraph 4 に non-type template parameters が持てる型について示されている(下線部は強調)。

A non-type template-parameter shall have one of the following (optionally cv-qualified) types:
- integral or enumeration type,
- pointer to object or pointer to function,
- lvalue reference to object or lvalue reference to function,
- pointer to member,
- std​::​nullptr_­t, or
- a type that contains a placeholder type.

“a type that contains a placeholder type” に関する記述 同ドラフト 10.1.7.4 The auto specifier [dcl.spec.auto]/paragraph 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.

autodecltype(auto)型指定子は、後で初期化子から差し引かれる placeholder type を指定するために使用され、同セクション/paragraph 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.

placeholder type はテンプレートパラメータ内のパラメータ宣言 decl-specifier-seqの宣言指定子として使用できる。