Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[temp.variadic] Rearrange description of pack expansion #4543

Merged
merged 1 commit into from Jun 18, 2021

Conversation

jensmaurer
Copy link
Member

@jensmaurer jensmaurer commented Mar 9, 2021

Fixes #4542

x1

x1

@jensmaurer jensmaurer requested a review from zygoloid March 9, 2021 11:31
@jensmaurer
Copy link
Member Author

@zygoloid , could you please have a look?

Copy link
Member

@zygoloid zygoloid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine; I have comments but they're mostly drive-by things. This change seems like an improvement to me.

github won't let me put comments on unchanged lines, but since I'm making drive-by comments anyway, I don't like the first bullet in the "Such an element [...] is interpreted as follows" list:

the element is a template parameter [..] designating [a] template argument

In the other bullets, we say the element is a (grammar term) designating a parameter. Saying in this case that the element is a parameter designating an argument seems wrong.

\pnum
The instantiation of a \tcode{sizeof...} expression\iref{expr.sizeof} produces
an integral constant containing the number of elements in the pack
it expands.
an integral constant with value $N$.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we say that sizeof...(Pack) expands the elements of the pack? I think that this isn't observable, even in the weird alias template cases where you end up with sizeof... applied to something that's not just the name of a pack, so this is probably fine, but it seems slightly surprising. Maybe the wording consistency is worth the modicum of surprise.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p7 status quo: "A pack whose name appears within the pattern of a pack expansion is expanded by that pack expansion."

What else do you want me to say?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I had interpreted that "is expanded by" as being a simple boolean property of the appearance of the pack, tying into the rule that all appearances of a pack need to be expanded, and not anything to do with substitution of the elements of the pack into some enclosing pattern.

But I think it's fine to leave this as you have it. Sure, we'll substitute into the identifier and produce a bunch of id-expressions / template-names/typedef-names naming the elements of the pack, then count them and drop them on the floor, but it doesn't matter that we do so.

source/templates.tex Outdated Show resolved Hide resolved
@jensmaurer
Copy link
Member Author

jensmaurer commented Mar 10, 2021

the element is a template parameter [..] designating [a] template argument

I've made this a little more regular, although the different kinds of template parameters make this a little bit more involved. Please have a look. (At least, you now have a hook where to apply your comments.)

The wish regarding N=0 has been implemented and force-pushed.

@jensmaurer
Copy link
Member Author

@zygoloid, is this more to your liking?

\pnum
The instantiation of a \tcode{sizeof...} expression\iref{expr.sizeof} produces
an integral constant containing the number of elements in the pack
it expands.
an integral constant with value $N$.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I had interpreted that "is expanded by" as being a simple boolean property of the appearance of the pack, tying into the rule that all appearances of a pack need to be expanded, and not anything to do with substitution of the elements of the pack into some enclosing pattern.

But I think it's fine to leave this as you have it. Sure, we'll substitute into the identifier and produce a bunch of id-expressions / template-names/typedef-names naming the elements of the pack, then count them and drop them on the floor, but it doesn't matter that we do so.

source/templates.tex Outdated Show resolved Hide resolved
source/templates.tex Outdated Show resolved Hide resolved
source/templates.tex Outdated Show resolved Hide resolved
(for a type template parameter pack declared with \tcode{template})
designating the $i^\text{th}$ template parameter
that resulted from instantiation of
the template parameter pack.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"that resulted from instantiation of the template parameter pack." seems like it's only suitable for the template parameter pack itself is a pack expansion(it might be non-type template pack or type template pack declared with template). So, Is it necessary to add a restriction to that sentence, that is "if the template parameter pack itself is a pack expansion"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing your point. Could you given an example, please?

Copy link
Contributor

@xmh0511 xmh0511 Mar 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jensmaurer My point is that "resulted from instantiation of the template parameter pack" sounds like the template parameter pack is a pack expansion, such a description would have the same effect as that of the function template parameter temp.variadic#8.2(which is itself a pack expansion). template<typename...T> struct A{ template<T...id> struct B{};};. In this example, the template parameter pack of the nested class template is a pack expansion itself, hence, when using the pack id in some context(form a pack expansion), we would say that replace id to designate ith template parameter that resulted from instantiation of the template parameter pack(namely, instantiate T...id to produce the result which consists of all elements of id {T0 id0, T1 id1,..., Tn idn}). However, a type template parameter pack declared without template is never a pack expansion. Furthermore, such a template<int...N> struct C{T b = {N...};}; where int...C is not a pack expansion and when instantiating the pattern N, each element merely designates the ith template parameter; I mean the result is not instantiated from something, instead, the set of elements of the parameter pack is merely obtained from the specified template arguments.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jensmaurer: any final thoughts on this?

@jensmaurer
Copy link
Member Author

@tkoeppe, updated. I think we should merge this and postpone @xmh0511's concerns to a separate issue (if there are any left).

@tkoeppe
Copy link
Contributor

tkoeppe commented Mar 17, 2021

Sorry, @jensmaurer, it was getting late and I went ahead and made the new working draft. Let's get this in for the next round.

@tkoeppe
Copy link
Contributor

tkoeppe commented Jun 17, 2021

I'll try to take another look so we can make this mailing.

@tkoeppe
Copy link
Contributor

tkoeppe commented Jun 18, 2021

Updated screenshot:

image

@xmh0511
Copy link
Contributor

xmh0511 commented Jun 18, 2021

Updated screenshot:

image

As aforementioned, For bullet 8.1, the attributive clause("that resulted from instantiation of the template parameter pack") is not completely suitable here. For instance, give the example template<class...T> struct A{using type = std::tuple<T...>;};, where class...T is not a pack expansion, How could we say that the typedef-name resulted from expanding T... designates the ith template parameter that resulted from instantiation of the template parameter pack? Conversely, for any parameter pack declaration that itself is also a pack expansion, that attributive clause has no problem.

@jensmaurer
Copy link
Member Author

The prior wording "designating the $i^\text{th}$ corresponding type or value template argument" was restored for case 8.1, fixing the regression.

@jensmaurer jensmaurer added this to the post-2021-06 milestone Jun 18, 2021
@jensmaurer jensmaurer merged commit 1e889e0 into cplusplus:master Jun 18, 2021
@jensmaurer jensmaurer deleted the c2 branch June 18, 2021 17:07
(for a type template parameter pack declared without \tcode{template}), or
a \grammarterm{template-name}
(for a type template parameter pack declared with \tcode{template})
if the pack was introduced by a pack expansion,
Copy link
Contributor

@xmh0511 xmh0511 Jun 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think "if the pack was introduced by a pack expansion" should be removed for bullet 8.1. For example, template<int...N> struct B{ B(){fun(N...);}};, Isn't that each element instantiated in N... does designate the corresponding template argument? However, int... N is just a template parameter pack declaration instead of a pack expansion(where the template parameter pack N is introduced by the parameter pack declaration). If add the condition seems that the latter clause is not suitable for this case. For type template parameter pack, it is the same. template<template<class T>... TMPL> struct C{using T = U<TMPL....>;};, template<class...T> struct D{using T = tuple<T...>;}, in all of these cases, the pack is introduced by the parameter pack declaration that is not a pack expansion itself, but each element actually does designate the ith template argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[temp.variadic] description of the instantiation of fold-expressions
4 participants