-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Adds a description of why we implement invoke as we do #368
Adds a description of why we implement invoke as we do #368
Conversation
The explination is from u/STL on reddit.
stl/inc/type_traits
Outdated
// it to be constexpr, yet variant visit() is required to be constexpr and have invoke-like behavior. We solve this by | ||
// using a macro to stamp out a public non-constexpr and internal constexpr implementation. | ||
|
||
// Now that a Core Language issue affecting constexpr invoke() has been fixed (CWG1581), we may make this unconditional |
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.
We wouldn't strengthen unconditionally, we would just make invoke call _C_invoke.
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 suppose, we'd also eliminate this macro and just expand it in the constexpr case right?
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.
There are throughput considerations here - std::function
is throughput-sensitive and it uses invoke()
. If invoke()
were defined to call _C_invoke()
, that would be an unnecessary layer of function calls.
I believe that the best thing to do would be to:
- De-macroize this machinery,
- Make the
_Invoker
layer unconditionallyconstexpr
, - Make
invoke()
conditionally_CONSTEXPR20
, - Change
apply()
andvisit()
to use the_Invoker
layer.
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.
Make the _Invoker layer unconditionally constexpr
Can we do that without CWG-1581?
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 don't think this conversation is relevant to documenting what's there now right.
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.
This affects your comment "Now that a Core Language issue affecting constexpr std::invoke has been fixed (CWG-1581), we may make this unconditional and remove the macro (which violates the strengthening rule in C++14/17 mode). TRANSITION, P1065R2" which talks about the future.
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.
yeah it seems like we may be able to do this without CWG-1581...
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.
yeah it seems like we may be able to do this without CWG-1581
I disagree; getting incorrect behavior from invoke is exactly why CWG-1581 existed in the first place. It's possible that Stephan's implementation, which does not use expression SFINAE, is immune to that problem, but I don't understand this area well enough to make such a firm statement. See http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2018/p1065r0.html for more nitty gritty details.
Co-Authored-By: Casey Carter <cartec69@gmail.com>
Co-Authored-By: Casey Carter <cartec69@gmail.com>
Co-Authored-By: Casey Carter <cartec69@gmail.com>
Co-Authored-By: Casey Carter <cartec69@gmail.com>
Co-Authored-By: Casey Carter <cartec69@gmail.com>
stl/inc/type_traits
Outdated
// it to be constexpr, yet variant visit() is required to be constexpr and have invoke-like behavior. We solve this by | ||
// using a macro to stamp out a public non-constexpr and internal constexpr implementation. | ||
|
||
// Now that a Core Language issue affecting constexpr invoke() has been fixed (CWG1581), we may make this unconditional |
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.
There are throughput considerations here - std::function
is throughput-sensitive and it uses invoke()
. If invoke()
were defined to call _C_invoke()
, that would be an unnecessary layer of function calls.
I believe that the best thing to do would be to:
- De-macroize this machinery,
- Make the
_Invoker
layer unconditionallyconstexpr
, - Make
invoke()
conditionally_CONSTEXPR20
, - Change
apply()
andvisit()
to use the_Invoker
layer.
Description
I ran across this comment on reddit from our very own @StephanTLavavej about why we need the
_IMPLEMENT_INVOKE
macro. I thought it was helpful and I had bounced off that particular macro a few times, so I added his explanation as a comment in the code (with some minor editing)Checklist
Be sure you've read README.md and understand the scope of this repo.
If you're unsure about a box, leave it unchecked. A maintainer will help you.
_Ugly
as perhttps://eel.is/c++draft/lex.name#3.1 or there are no product code changes.
verified by an STL maintainer before automated testing is enabled on GitHub,
leave this unchecked for initial submission).
members, adding virtual functions, changing whether a type is an aggregate
or trivially copyable, etc.).
the C++ Working Draft (including any cited standards), other WG21 papers
(excluding reference implementations outside of proposed standard wording),
and LWG issues as reference material. If they were derived from a project
that's already listed in NOTICE.txt, that's fine, but please mention it.
If they were derived from any other project (including Boost and libc++,
which are not yet listed in NOTICE.txt), you must mention it here,
so we can determine whether the license is compatible and what else needs
to be done.