[英]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.
现在,我声明struct isPtrToMemberFunc,然后向每个类添加一个额外的模板(类TType = void)(现在仅为1),并专门化该额外的模板以查看其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. 有一种方法,但是它包括对这些成员函数的每个数量的参数和const / volatile修饰符重复专门化操作。 An easier way to do that is to use
boost.functiontypes
which does that for you: 一种更简单的方法是使用
boost.functiontypes
为您boost.functiontypes
这一点:
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";
// ...
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.