The general idea can be found here. The idea is to write a template which wraps function. Template takes as an argument pointer to the function.
Implementation:
#include <utility>
template <class F, F f> struct wrapper;
template <class R, class... Args, R (*f)(Args...)>
struct wrapper<R (*)(Args...), f> {
static R call(Args... args) {
// ...
return f(args...)
}
};
Usage:
int foo(int);
auto bar(int n) {
return wrapper<decltype(&foo), &foo>::call(n);
}
Implementation:
#include <utility>
template <auto f> struct wrapper;
template <class R, class... Args, R (*f)(Args...)>
struct wrapper<f> {
static R call(Args... args) {
// ...
return f(args...);
}
};
Usage:
int foo(int);
auto bar(int n) {
return wrapper<foo>::call(n);
}