Consider an overloaded function
void f(int);
void f(long);
void f(double);
void f(MyClass);
And a method in a template class with unknown argument type
template <class T>
struct C {
void method(T arg) { ... }
};
I want to check at compile time if there is a version of f
which can take arg
as an argument.
template <class T>
struct C {
void method(T arg) {
if constexpr (CAN_BE_CALLED(f, arg)) {
f(arg);
} else {
g();
}
}
};
Is it possible to do that? I tried this and this but compiler complained about unresolved overloaded function type.