admin管理员组文章数量:1336643
Let me use last current draft for clause about placeholder type deduction: ++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
).
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
).
1 Answer
Reset to default 2[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)
.
本文标签: cMultiple occurrences of placeholder type 39auto39 in a typeStack Overflow
版权声明:本文标题:c++ - Multiple occurrences of placeholder type 'auto' in a type - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742343992a2457153.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
language-lawyer
tag to attract more knowledgeable users – 463035818_is_not_an_ai Commented Nov 22, 2024 at 13:05