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
Conversation
@zygoloid , could you please have a look? |
There was a problem hiding this 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$. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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. |
@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$. |
There was a problem hiding this comment.
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
(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. |
There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
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. |
I'll try to take another look so we can make this mailing. |
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 |
The prior wording "designating the |
(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, |
There was a problem hiding this comment.
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.
Fixes #4542