简体   繁体   中英

is it possible to detect pointer-to-member-function?

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM