c++ - Multiple occurrences of placeholder type 'auto' in a type - Stack Overflow

Let me use last current draft for clause about placeholder type deduction: ++draftdcl.type.auto.deduct

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′ 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).

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).

Share Improve this question edited Nov 24, 2024 at 22:03 user20575107 asked Nov 20, 2024 at 16:37 user20575107user20575107 1497 bronze badges 6
  • after trying to make sense of it for a while I am starting to wonder if its a typo and intended meaning is " Obtain P from T by replacing the type-constraint(opt) auto either with a new invented type ...". This would also match with the beginning of the paragraph where "If the placeholder-type-specifier is of the form..." talks about 1 occurence. Though, I might be totally wrong – 463035818_is_not_an_ai Commented Nov 20, 2024 at 17:38
  • its all singular only this sentence mentions "occurences" – 463035818_is_not_an_ai Commented Nov 20, 2024 at 17:39
  • I have tried already to think to that first part "If the placeholder-type-specifier is of the form...", but it may still be compatible with the plural 'occurrences', as part 2 reads 'A type T containing a placeholder type...' which means that T contains one (or more) placeholders, and then the contained placeholder(s?) may be in the form of 'auto'. Again, part 5 is much more clear when, for the case of 'decltype(auto)', it requires that T must only be composed by that (single) placeholder, so confirming that part 2 is more general. A wider generality might also be related to other specifiers. – user20575107 Commented Nov 20, 2024 at 19:44
  • If you guys confirm that plural does not lead you to think to real examples, I will enrich this thread std-discussion including also about this 'occurrences'. – user20575107 Commented Nov 20, 2024 at 19:46
  • dont rely on my comments. My standardese is rather crappy. Perhaps add the language-lawyer tag to attract more knowledgeable users – 463035818_is_not_an_ai Commented Nov 22, 2024 at 13:05
 |  Show 1 more comment

1 Answer 1

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).

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742343993a4426177.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信