对于普通的香草功能,它工作得很好。下面的代码工作得很好。它只打印应该的内容:
int __cdecl(int, char)
2
int,char
#include <boost/type_traits.hpp>
#include <boost/function.hpp>
#include <boost/typeof/std/utility.hpp>
#include <iostream>
using std::cout;
using std::endl;
int foo(int, char) {
return 0;
}
int main() {
typedef BOOST_TYPEOF(foo) foo_type;;
typedef boost::function_traits<foo_type> function_traits;
cout << typeid(foo_type).name() << endl;
cout << function_traits::arity << endl;
cout << typeid(function_traits::arg1_type).name() << ",";
cout << typeid(function_traits::arg2_type).name() << endl;
return 0;
}
所以,问题是,如果 foo 是类 bar 的成员函数,怎么能做到这一点?
struct bar {
int foo(int, char) { return 0; }
};
我已经尝试过无数种这些结构的组合: BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() BOOST_TYPEOF_REGISTER_TYPE() boost::ref boost::remove_pointer boost::bind boost::mem_fn
等等,等等……没有喜悦。