Created
August 14, 2023 09:36
-
-
Save iains/fc53cdfdf55c383d1d33ba1c2850052a to your computer and use it in GitHub Desktop.
using a lambda trampoline - to making a closure into a function ptr.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Closure type that runs the original function with the supplied args. | |
auto __callable = [&] { | |
std::__invoke(std::forward<_Callable>(__f), | |
std::forward<_Args>(__args)...); | |
}; | |
// Trampoline to call the actual fn; we will pass in the closure address. | |
void (*__oc_tramp)(void*) | |
= [] (void *ca) { (*static_cast<decltype(__callable)*>(ca))(); }; | |
now you can call __oc_tramp ( std::addressof (__callable) ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment