-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[RFC] Type stable wrapper for arbitrary callables #13984
Comments
I'd like to advocate for this being in stdlib sooner rather than later, my arguments are as follows:
I know it has been stated repeatedly that this is experimental, but it certainly already offers quite a bit of functionality which, again, is otherwise unobtainable. Any interest in doing this? Any ideas what else would be required? (I wish I could offer to be more helpful, but this is well beyond my expertise.) |
I recently had the need for this and totally support the idea. Cool stuff 👍 |
Thanks Oscar Smith for pointing out #55111 is implementing this |
This isn't completed. #55111 isn't merged. |
The idea is to have an equivalent of function pointer in C or
std::function
in C++11. This could be useful to avoid over specialization (Ref #13412 (comment)) and also for implementing mutable callback list/table. In these cases, it is acceptable that the callback function is not/cannot be inlined to the caller but it is also desired to avoid necessary boxing or runtime type check/dispatch.One way to implement something like this is to use
cfunction
. I've hacked together a proof of concept implementation here. It is very non-generic and is not ideal due to the limitations ofcfunction
(no vararg, no way to bypass type checks, for example). Nevertheless, the benchmark comparing calling two functors stored in aUnion
array and an array with this wrapper shows that calling with the wrapper is ~40 times faster and avoids the necessary boxing of the arguments and results.A few features that I think should be included:
cfunction
)@JeffBezanson Is there anything related that is planed / implemented for #13412 ?
The text was updated successfully, but these errors were encountered: