Is there a way, using SFINAE, to determine if a free function is overloaded for a given class?
Basically, Ive got the following solution:
struct has_no_f { }; struct has_f { }; void f(has_f const& x) { } template <typename T> enable_if<has_function<T, f>::value, int>::type call(T const&) { std::cout << "has f" << std::endl; } template <typename T> disable_if<has_function<T, f>::value, int>::type call(T const&) { std::cout << "has no f" << std::endl; } int main() { call(has_no_f());
Just call overloading does not work, because in fact there are many types foo and bar , and the call function does not know about them (basically call is inside a, and users provide their own types).
I cannot use C ++ 0x, and I need a working solution for all modern compilers.
Note: the solution for a similar question , unfortunately, does not work here.
c ++ templates sfinae
Konrad Rudolph
source share