Last active
October 16, 2023 13:53
-
-
Save beto-bit/f7ad413be21f2f4a94379dae289f5ba0 to your computer and use it in GitHub Desktop.
Function Pointer wrapper with zero overhead
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
template<typename Signature> | |
struct FuncPtr; | |
template<typename ReturnType, typename... Args> | |
struct FuncPtr<ReturnType(Args...)> { | |
ReturnType (*func_ptr)(Args...); | |
FuncPtr(ReturnType (*func)(Args...)) : func_ptr(func) {} | |
ReturnType operator()(Args... args) { | |
return func_ptr(args...); | |
} | |
}; | |
template<typename ReturnType, typename... Args> | |
FuncPtr(ReturnType (*func_ptr)(Args...)) -> FuncPtr<ReturnType(Args...)>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment