Nathan Ridge a écrit :
Anyway, if you want to test the signature of a function object, just
take the address of &T::operator() and check it is what you want. Of
course that won't work if it's a template or if it is overloaded.
Could you be kind enough to give an example of how I can do such a check?
This works on GCC, haven't tested with other compilers.
#include
#include
#include
#include
#include
#include
template struct function_to_member
{
typedef typename
boost::function_types::result_type<Prototype>::type result;
typedef typename
boost::function_types::parameter_types<Prototype>::type args;
typedef typename boost::mpl::push_front::type
base;
typedef typename boost::mpl::push_front::type
type;
};
template struct build_member_type
{
typedef typename function_to_member::type
root;
typedef typename
boost::function_types::member_function_pointer<root>::type type;
};
template struct build_const_member_type
{
typedef typename function_to_member::type root;
typedef typename boost::function_types::member_function_pointer<
root,
boost::function_types::const_qualified
>::type type;
};
template
struct has_signature
{
typedef char not_found;
struct found { char x[2]; };
template::type>
struct member {};
template::type>
struct const_member {};
template<typename X> static found test(member*);
template<typename X> static found test(const_member*);
template<typename X> static not_found test(...);
static const bool value = (sizeof(found) == sizeof(test<T>(0)));
typedef boost::mpl::bool_<value> type;
};
example of use:
struct foo { int operator()(short) const; };
struct bar { int operator()(short); };
struct baz { int operator()(int); };
int main()
{
std::cout << has_signature::value << std::endl; // 1
std::cout << has_signature::value << std::endl; // 1
std::cout << has_signature::value << std::endl; // 0
}