Hi,
I only needed to check for member functions.
I don't know how to put in all the crazy boost compiler workarounds.
I'd like to hear of any ideas for ways to make it better.
- Sniv
#include
//
----------------------------------------------------------------------------
typedef char (&false_tag)[1];
typedef char (&true_tag)[2];
template <bool> struct bool_tag;
template <> struct bool_tag<false> { typedef false_tag type; };
template <> struct bool_tag<true> { typedef true_tag type; };
template struct size_bool;
template <> struct size_bool { static const
bool value = true; };
template <> struct size_bool { static const
bool value = false; };
//
----------------------------------------------------------------------------
template <typename T> struct get_class;
template struct get_class { typedef C
type; };
template struct get_class {
typedef C type; };
template struct get_class { typedef C type; };
template struct
get_class { typedef C type; };
template struct get_class { typedef C type; };
template struct get_class {
typedef C type; };
template struct get_class { typedef C type; };
template struct get_class { typedef C type; };
template struct
get_class { typedef C type; };
template struct get_class { typedef
C type; };
template struct get_class { typedef C type; };
//
----------------------------------------------------------------------------
#define HAS_XXX_MEMBER_FUNCTION_NAMED_DEF(MEMBER) \
HAS_XXX_MEMBER_FUNCTION_DEF(BOOST_PP_CAT(has_, MEMBER), MEMBER) \
#define HAS_XXX_MEMBER_FUNCTION_DEF(NAME, MEMBER) \
template <typename _Sig> \
struct NAME \
{ \
template <_Sig> struct pmf_helper {}; \
template <class T> static bool_tag<false>::type test(...); \
template <class T> static bool_tag<true>::type
test(pmf_helper<&T::MEMBER>*); \
static const bool value = size_bool::type>(0))>::value; \
}; \
//
----------------------------------------------------------------------------
struct Test1 { void f(); };
struct Test2 { int f(bool); };
struct Test3 {};
HAS_XXX_MEMBER_FUNCTION_NAMED_DEF(f)
int main()
{
cout << has_f::value << endl;
cout << has_f::value << endl;
cout << has_f::value << endl;
}