I have taken a look at anything I could find through Boost lists and Google that came up as
a solution to the problem of detecting the existence of a member function in
a type... using SFINAE.
All of them have one problem.. they are unable to detect the existence of
the member function if it was defined in a base class. They can only detect
if the member function was directly defined in the class being tested.
At their heart, all solutions boil down to some variation of the following
template class with a template parameter that is a (non-type) pointer to
member function:
template
struct Tester;
Then we try to SFINAE on it by the usual sizeof trick.
However the problem is that if method 'void foo(int)' is defined in a Base
class. Then the type of &Derived::foo is actually void (Base::*)(int) ...
and not void (Derived::*)(int)
Although during argument passing the conversion of the Base member function
pointer to Derived member function pointer is acceptable to C++, it will
NOT do such conversion when instantiating templates.
So trying to use Tester will always fail us if 'foo'
is defined in Base.
So .. my question is ....does anyone have solution that works for the case
when the method is defined in the base class too ?
I am thinking ... if it is possible to extract the class name from the
actual type of &Derived::foo, then the problem can be solved... but the type
extraction mechanism must not error out on types that have absolutley no
member function called foo.
I know type erasure (which i prefer to call External polymorhism) can solve this issue
but SFINAE is more efficient at runtime.
-Roshan