Reputation: 149
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′
replacingT
is determined using the rules for template argument deduction. If the initialization is copy-list-initialization, a declaration ofstd::initializer_list
shall precede ([basic.lookup.general]) the placeholder-type-specifier. ObtainP
fromT
by replacing the occurrences of type-constraint(opt) auto either with a new invented type template parameterU
or, if the initialization is copy-list-initialization, withstd::initializer_list<U>
. Deduce a value forU
using the rules of template argument deduction from a function call, whereP
is a function template parameter type and the corresponding argument isE
. If the deduction fails, the declaration is ill-formed. Otherwise,T′
is obtained by substituting the deducedU
intoP
.
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
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