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] description of the instantiation of fold-expressions #4542
Comments
I think the description is clear that N=0 means the result of a binary fold is E. For the first point, I think I agree the presentation could be improved by first introducing E_i (in general) and then explaining where those appear. |
For the second point, I don't think it's clear. In paragraph 10, the rule only states how the result would be for a unary fold-expression when the element of the pack expansion parameter is empty, It does not talk about binary fold-expression in this case. Although there's a rule possibly relate to the case, which inhabits at the end of paragraph 8, that is:
However, at this time, I think the rule prefers to describe the case for "The instantiation of a pack expansion that is neither a sizeof... expression nor a fold-expression..." when N is zero. Consider this example #include <iostream>
template<class...T>
void fun(T...args){
std::initializer_list<bool> c = {true&&args...};
std::cout<< c.size()<<std::endl; // its result is 0
std::initializer_list<bool> c2 = {(true&&...&&args)};
std::cout<< c2.size()<<std::endl; // its result is 1
}
int main() {
fun();
} The size of |
I'm saying that the syntactic expansion described for binary fold-expressions in p10 does work for N=0, and thus N=0 does not need a special case in the prose wording. |
Maybe I see your meaning. Do you mean op and Ei are pair-wise? |
Sort-of. Look at the expansion of a unary fold: ((E 1 op E 2 ) op · · · ) op E N What's the result for N=1? It's E_1 (there is no E_2 at all). Now look at binary fold: (((E op E 1 ) op E 2 ) op · · · ) op E N What's the result for N=0? With analogy to the foregoing, it's obviously E (there is no E_i at all). |
Thanks. That's my understanding of what you are saying. That is, from right to left the op and its subsequent expression are viewed as an instantiated component. |
In the current draft, there are two issues about the instantiation for a fold-expression.
The first is the standard seems not clear for stating which are the elements of the pack expansion parameters that appear in the pattern of fold-expression. It could be assumed they're stated in paragraph 8 temp.variadic#8.
However, such a layout of the rule seems that the description for what these elements of pack expansion parameters are is only applying to the case that is:
the instantiation of a pack expansion that is neither a sizeof... expression nor a fold-expression
.Is it necessary to take the rule out from paragraph 8 to be an individual rule? That would clearly cover the case that what these elements of the pack expansion parameters are which appears in the fold-expression.
The second issue is about the binary fold-expression when the number of the elements is zero. The whole paragraph 10 only talks about how the result is for the unary fold-expression when the number of the elements is zero. It lacks the case of a binary fold-expression. (Presumably, the result of this case is that of the expression
E
).Such as this example, even though the first operand &a would violate expr.mptr.oper#2
The text was updated successfully, but these errors were encountered: