You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks! There are two examples here, taking them one by one...
f: <T> (_: std::vector<T>) = { }
You're right, I should include that in the "hey this is using a template parameter name" deduced-type case.
I've done that now in the above commit -- please check?
f: <T: std::regular> (_: T) = { }
This is using the value parameter syntax (see NOTE), so in this position Cpp2 expects std::regular is a type (not a concept). I realize that Cpp1 allows a concept name in the analogous position, but Cpp2 aims to have a syntax that does not require name lookup to decide what something is (either actual name lookup in the compiler, or even just visual name lookup for the programmer to figure it out), so my stake in the ground is that anything of this form should mean "value."
Today you can express this using requires, like this
and make it lower to the same thing. But for now the answer is requires... as a user who encountered and reported this, does that seem like a reasonable answer to you? (Be frank!)
(NOTE) In general in parameters of templated type T are emitted as const T& for this reason, so this
// A type parameter says 'type' (possibly implicitly)
f: <T: type> (_: T) = { }
Activity
JohelEGP commentedon Apr 23, 2023
Minimal reproducer (https://godbolt.org/z/3v8b36s3q):
Commands:
cppfront x.cpp2 clang++17 -std=c++2b -stdlib=libc++ -I $CPPFRONT_INCLUDE_DIR x.cppExpected result:
Actual result and error:
Full generated Cpp1.
hsutter commentedon Apr 23, 2023
Thanks! There are two examples here, taking them one by one...
f: <T> (_: std::vector<T>) = { }You're right, I should include that in the "hey this is using a template parameter name" deduced-type case.
I've done that now in the above commit -- please check?
f: <T: std::regular> (_: T) = { }This is using the value parameter syntax (see NOTE), so in this position Cpp2 expects
std::regularis a type (not a concept). I realize that Cpp1 allows a concept name in the analogous position, but Cpp2 aims to have a syntax that does not require name lookup to decide what something is (either actual name lookup in the compiler, or even just visual name lookup for the programmer to figure it out), so my stake in the ground is that anything of this form should mean "value."Today you can express this using
requires, like thiswhich lowers to this
I've thought of supporting a syntactic sugar for this case along the lines of
and make it lower to the same thing. But for now the answer is
requires... as a user who encountered and reported this, does that seem like a reasonable answer to you? (Be frank!)(NOTE) In general
inparameters of templated typeTare emitted asconst T&for this reason, so thisor its short form
lowers to this
Note that the syntax for non-type (value) parameters is the same as for objects, so this
lowers to this
JohelEGP commentedon Apr 23, 2023
The generated code looks good now.
Yes! I felt something was odd, but couldn't quite grasp it.
Also detect dependent parameter types of the form `something<...,T,..…
Also detect dependent parameter types of the form `something<...,T,..…