user20575107
user20575107

Reputation: 149

Multiple occurrences of placeholder type 'auto' in a type

Let me use last current draft for clause about placeholder type deduction: https://eel.is/c++draft/dcl.type.auto.deduct

Part 3 reads (bold highlighting from me):

If the placeholder-type-specifier is of the form type-constraint(opt) auto, the deduced type T′ replacing T is determined using the rules for template argument deduction. If the initialization is copy-list-initialization, a declaration of std​::​initializer_list shall precede ([basic.lookup.general]) the placeholder-type-specifier. Obtain P from T by replacing the occurrences of type-constraint(opt) auto either with a new invented type template parameter U or, if the initialization is copy-list-initialization, with std​::​initializer_list<U>. Deduce a value for U using the rules of template argument deduction from a function call, where P is a function template parameter type and the corresponding argument is E. If the deduction fails, the declaration is ill-formed. Otherwise, T′ is obtained by substituting the deduced U into P.

May anyone share any example with multiple occurrences of (optionally type-constrained) auto within type T, intended to be the same type P?

For example, part 4 with the case of decltype(auto), explictly state the constraint:

... T shall be the placeholder alone ...

which seems to confirm that extended cases exist (for auto).

Upvotes: 3

Views: 130

Answers (1)

Davis Herring
Davis Herring

Reputation: 40023

[dcl.spec.auto.general]/5 specifies how a placeholder type can be used to declare a variable. It has to be used as a decl-specifier, as opposed to in a nested declarator:

void f(int,float);
void (*p)(auto,auto)=f;  // error: no auto here

So there’s no possibility of using more than one: I suppose the wording is just written generally, although one would expect a mention of potentially multiple synthesized template parameters in that case.

[dcl.type.auto.deduct]/4 is just saying that you can’t use a type-constraint with decltype(auto).

Upvotes: 2

Related Questions