-
Notifications
You must be signed in to change notification settings - Fork 261
[SUGGESTION] Add inspect alternatives for literals #79
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
[SUGGESTION] Add inspect alternatives for literals #79
Conversation
a88bbb3
to
c49ceb1
Compare
c49ceb1
to
f4866cf
Compare
f4866cf
to
04e7701
Compare
04e7701
to
a0e99b0
Compare
Rebase to main. Make |
a0e99b0
to
50b7932
Compare
599f007
to
921ed9f
Compare
921ed9f
to
2c21174
Compare
Thanks! This also has some |
Check the literals part. I will check the commits. Give me a minute. |
2c21174
to
b7668e9
Compare
Ahh... I was rebasing yesterday to resolve this dependency and forgot to push. Now fixed. |
OK, it's mostly clean, but GCC 10.3 is having trouble with the Also, I'm trying out variations of your code to support also non-literals. More soon... |
OK, I think I have it... thanks for prodding me about inspecting to match values. I've taken inspiration from this PR and followed your basic parsing implementation (looks exactly right, thanks!) and I'll apply it in a separate commit because I reworked the basic implementation in
This is the direction I had in mind for the "is value" case in P2392 which has "use
So whereas for the "is type" case we still emit Granted, this doesn't force literals to be processed at compile time, but if that's an issue we can optimize later... and even now the literal is visible in the generated Cpp1 source, and it's just a single one-line inlined function away from the call site, so I'm optimistic the Cpp1 compiler will pick it up after inlining. (The eventual most aggressive optimization would be to optimize a series of Here is my test case:
This (now) prints:
The one inelegant thing right now is the parens required for the Thanks for prompting this! I harvested your basic parser implementation and it was fine, I just changed the names a little, most of the change was the above generalization in |
Excellent! I like the simplicity of this solution. I was afraid that my solution was too complicated. |
That approach will probably simplify also use of the functions/unnamed functions in that context: #90 |
Now that I've done the support requested in #90: Yes it did simplify it, but only after a lot of fiddling with |
Also cleaned up _alternative_ to use _type-id_ rather than _id-expression_.
The current implementation of alternatives for inspect handles only types. It makes it impossible to replace the cpp1 switch with it. This change brings support for literals in alternatives which makes it possible to use as in given example:
The implementation of specializations of
is()
functions is complicated by the fact that the support for Non-Type Template Parameters (NTTP) is not fully (uniformly) implemented in GCC, clang, and MSVC. I have made a lot of tests to find a solution with workarounds that will not require preprocessor ifs for the specific compiler but one issue in clang makes me use it (probably a bug in clang). A working prototype of the solution is available here: https://godbolt.org/z/j1fqWKa9G (if you have any idea how to improve the implementation please let me know).One of the supported NTTPs is
double
but there is an issue in clang and MSVC with it which was solved by introducing an intermediate typedouble_wrapper
that makes it work for clang and MSVC. Unfortunately, it additionally needs a special version ofis()
function that makes the magic work for clang.During my experiments, I have been studying https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2392r0.pdf to understand the feature.
This PR makes #74 obsolete - enums are also covered by this implementation. Closes #73