I created a small function wrapper example. I want to make the wrapper consider whether or not the function called is using (const) references, meaning the output will be 4/5 and not 4/4, but I don't want to enforce reference usage if the wrapped function does not use them.
#include <iostream>
#include <string>
struct a {
static void run(int cref) {
cref = 5;
};
};
struct b {
static void run(int &cref) {
cref = 5;
};
};
template <class FTor>
struct foo {
template <class ... Args>
static void wrapper(Args ... args) {
FTor::run(args ...);
}
};
int main()
{
int bar = 4;
foo<a>::wrapper(bar);
std::cout << bar;
foo<b>::wrapper(bar);
std::cout << bar;
}