X f(Concept{T}&& a){ /* ... */ }
X f(Concept{}); //forward function declaration
X h(int{}); //new variable
Foo a(X()); //function, even if I wanted variable
Foo b(Y(1)); //variable
Foo f(Z{}); //C++11: always variable, C++20: ??, you need to know what Z is
In p0745r0 is introduced new syntax:
X f(Concept{T}&& a){ /* ... */ }
But after looking on it I get feeling this could end up in new most vexing parse MK 2:
X f(Concept{}); //forward function declaration
X h(int{}); //new variable
Is this valid concern?
Is possible that someone write code that will have opposite meaning than intended? Can same concept and type name exist in same scope?
Probably one thing for sure we will loose is ability automatic visual distinction:
Foo a(X()); //function, even if I wanted variable
Foo b(Y(1)); //variable
Foo f(Z{}); //C++11: always variable, C++20: ??, you need to know what Z is
Foo f(Z); //May declare a template or non-template function; you need to know what Z is.
On Monday, April 9, 2018 at 9:33:58 AM UTC-4, Marcin Jaczewski wrote:
In p0745r0 is introduced new syntax:
X f(Concept{T}&& a){ /* ... */ }
But after looking on it I get feeling this could end up in new most vexing parse MK 2:
X f(Concept{}); //forward function declaration
X h(int{}); //new variable
Is this valid concern?
Nope. In order for that to compile, the compiler must see the declaration of `Concept`. And therefore, the compiler can see that `Concept` is a concept, not a typename. And therefore, the compiler knows what that is.
Now, it may be that the user is confused, but never the compiler.
Is possible that someone write code that will have opposite meaning than intended? Can same concept and type name exist in same scope?
Concepts are variables, and you can't have a typename and variable with the same name in the same scope.Probably one thing for sure we will loose is ability automatic visual distinction:
Foo a(X()); //function, even if I wanted variable
Foo b(Y(1)); //variable
Foo f(Z{}); //C++11: always variable, C++20: ??, you need to know what Z is
And how is that any different from:
Foo f(Z); //May declare a template or non-template function; you need to know what Z is.
If you want good terse syntax, you're going to have to give up some form of visual inspection. C++ is out of good syntax for this sort of stuff, so we have to make due with what we have.
template<Concept{T}> class A{}; // A<int>, T == int
template<Concept{T} V> class B1{}; // B1<5>
template<Concept{T} /*V*/> class B2{}; //ups, now is type not value parameter
Besides, I would say that from the surrounding context, you'll know which is which. If its in a function, odds are good `Z` is a typename. If its in class scope, `Z` *must* be a concept, since you can't use parenthesis on default member initializers. If its in global scope, `Z` is probably a concept, since you'd usually write it as `Foo f = Z{};`. Also, concept names are not likely to be confused with typenames.
On Monday, April 9, 2018 at 4:06:37 PM UTC+2, Nicol Bolas wrote:
On Monday, April 9, 2018 at 9:33:58 AM UTC-4, Marcin Jaczewski wrote:
In p0745r0 is introduced new syntax:
X f(Concept{T}&& a){ /* ... */ }
But after looking on it I get feeling this could end up in new most vexing parse MK 2:
X f(Concept{}); //forward function declaration
X h(int{}); //new variable
Is this valid concern?
Nope. In order for that to compile, the compiler must see the declaration of `Concept`. And therefore, the compiler can see that `Concept` is a concept, not a typename. And therefore, the compiler knows what that is.
Now, it may be that the user is confused, but never the compiler.
This is whole point. In most vexing parse compiler is not confused too but user is.
Is possible that someone write code that will have opposite meaning than intended? Can same concept and type name exist in same scope?
Concepts are variables, and you can't have a typename and variable with the same name in the same scope.Probably one thing for sure we will loose is ability automatic visual distinction:
Foo a(X()); //function, even if I wanted variable
Foo b(Y(1)); //variable
Foo f(Z{}); //C++11: always variable, C++20: ??, you need to know what Z is
And how is that any different from:
Foo f(Z); //May declare a template or non-template function; you need to know what Z is.
How it could declare template in `C++17`?
On Monday, April 9, 2018 at 11:10:27 AM UTC-4, Marcin Jaczewski wrote:On Monday, April 9, 2018 at 4:06:37 PM UTC+2, Nicol Bolas wrote:
On Monday, April 9, 2018 at 9:33:58 AM UTC-4, Marcin Jaczewski wrote:
In p0745r0 is introduced new syntax:
X f(Concept{T}&& a){ /* ... */ }
But after looking on it I get feeling this could end up in new most vexing parse MK 2:
X f(Concept{}); //forward function declaration
X h(int{}); //new variable
Is this valid concern?
Nope. In order for that to compile, the compiler must see the declaration of `Concept`. And therefore, the compiler can see that `Concept` is a concept, not a typename. And therefore, the compiler knows what that is.
Now, it may be that the user is confused, but never the compiler.
This is whole point. In most vexing parse compiler is not confused too but user is.
In the most vexing parse, the compiler is not doing what the user expected. You wrote a typename followed by parenthesis, expecting this to mean "default construct a prvalue of this type". The compiler sees a typename followed by parenthesis and assumes this means "function type". The code doesn't do what the user thought it would.
That's not the case here. You wrote a concept name followed by curly braces, expecting this to mean "concept constrained parameter". The compiler agrees with you. So there is no confusion.
The most vexing parse is about the confusion between the writer and the compiler. That's not what's happening here. If there is confusion, it is only between the reader and the writer/compiler. The writer's intent and the compiler's actions are in alignment. The writer knew it was a concept name, and the compiler agreed.
On Monday, April 9, 2018 at 9:33:58 AM UTC-4, Marcin Jaczewski wrote:
In p0745r0 is introduced new syntax:
X f(Concept{T}&& a){ /* ... */ }
But after looking on it I get feeling this could end up in new most vexing parse MK 2:
X f(Concept{}); //forward function declaration
X h(int{}); //new variable
Is this valid concern?
Nope. In order for that to compile, the compiler must see the declaration of `Concept`. And therefore, the compiler can see that `Concept` is a concept, not a typename. And therefore, the compiler knows what that is.
Now, it may be that the user is confused, but never the compiler.
Is possible that someone write code that will have opposite meaning than intended? Can same concept and type name exist in same scope?
Concepts are variables, and you can't have a typename and variable with the same name in the same scope.Probably one thing for sure we will loose is ability automatic visual distinction:
Foo a(X()); //function, even if I wanted variable
Foo b(Y(1)); //variable
Foo f(Z{}); //C++11: always variable, C++20: ??, you need to know what Z is
And how is that any different from:
Foo f(Z); //May declare a template or non-template function; you need to know what Z is.
If you want good terse syntax, you're going to have to give up some form of visual inspection.
C++ is out of good syntax for this sort of stuff, so we have to make due with what we have.
Besides, I would say that from the surrounding context, you'll know which is which. If its in a function, odds are good `Z` is a typename. If its in class scope, `Z` *must* be a concept, since you can't use parenthesis on default member initializers. If its in global scope, `Z` is probably a concept, since you'd usually write it as `Foo f = Z{};`. Also, concept names are not likely to be confused with typenames.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/b1082776-de1a-4f25-bcc2-739dcc6897ab%40isocpp.org.