|
Boost : |
From: Nikolay Mladenov (nikolay.mladenov_at_[hidden])
Date: 2007-07-26 11:39:23
Hello,
I am working on a patch for Boost.Python and
I need to find a portable way of detecting if a static member function
(with fixed name and signature) is declared in a class.
So far I have tried the following (testing if "static int *get_int()"
is declared):
typedef char yes_type;
typedef struct {char a[2]; } no_type;
template<int * (*f)()> struct test_get_int1 { };
template<class T> yes_type get_int_tester(test_get_int1<&T::get_int>*);
template<class T> no_type get_int_tester(...);
template<class T>
struct test_get_int_base
{
BOOST_STATIC_CONSTANT(bool, value= (sizeof(get_int_tester<T>(0)) ==
sizeof(yes_type)));
};
template<class T>
struct test_get_int : boost::mpl::bool_<test_get_int_base<T>::value>
{
};
this works on some compilers : msvc7.1, msvc8.0, gcc3.4, gcc4.1.0, gcc4.1.2
but not on gcc3.2: when get_int is not present it complains "get_int
is not member of type..."
and strangely not on gcc4.1.1: when get_int is present it complains
"static int *T::get_int cannot be a template parameter because is not
of external linkage"
I have not tried other compilers but I expect more of the same problems.
Can anyone suggest a better way of doing this?
Thanks in advance,
Nikolay Mladenov
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk