views:

107

answers:

1

i want a specialize template in a pointer-to-member-function case. Is there a way to detect this? right now i declare struct isPtrToMemberFunc, then add an extra template (class TType=void) to each class (right now just 1) and specialize the extra template to see if its isPtrToMemberFunc. Is there a way to detect this automatically? if not is my current method the best solution?

+5  A: 

There is a way, but it includes that you repeat your specialization for each and every number of arguments and const/volatile modifiers for those member functions. An easier way to do that is to use boost.functiontypes which does that for you:

template<typename T>
void doit(T t) {
    if(boost::function_types::is_member_function_pointer<T>::value) {
        std::cout << "it is";
        // ...
    } else {
        std::cout << "it is not";
        // ...
    }
}

Grab it from here.

Johannes Schaub - litb