I currently use this code in C++ to call a function pointer if it isn’t null (I have a few events like onCreate, onDestroy, etc, that are function pointers that can be assigned):
#define AssertiveCall(_fn, _args) \
{ \
if (_fn != nullptr) \
{ \
return (_fn##_args); \
} \
}
I would like to convert this into a template, so that I still get the benefit of shorthand but without the ugliness of the #define macro. How could I do it?
For reference, an implementation with variadic templates – in case somebody else has a similar problem and can use variadic templates: