Boost logo

Boost :

From: Jonathan Turkanis (technews_at_[hidden])
Date: 2004-11-15 17:31:24

"Bronek Kozicki" <brok_at_[hidden]> wrote in message
> Jonathan Turkanis wrote:
> > Hi All,
> >
> > I'm writing a macro-based interface definition language, which I hope to
> > post soon. For this, I need to be able to detect the presence of member
> > functions with given name and signature. My current formulation generates
> > like the following to test whether a class has a non-const member function
> > 'one' with the signature char(int, float):


> template <typename Type>
> class has_member__one
> {
> // 1. SIGNATURE goes here
> template <char (Type::*)(int, float)> struct helper{};
> typedef char (&yes) [1];
> typedef char (&no) [2];
> template <typename Type_>
> // 2. NAME goes here
> static yes test (helper<&Type_::one>*);
> template <typename Type_>
> static no test (...);
> public:
> enum {value = sizeof(test<Type>(0)) == sizeof(yes)};
> };

Hi Bronek,

Thanks for your effort coming up with this workaround. Unfortunately, although
it works okay (when modified as described below) in isolation, when it is
generated by macros as a deeply nested template, something goes wrong and it
doesn't handle overloading.

I'd like to point out two things about the above implementation, for anyone who
might be following this thread.

1. I believe it is non-conforming, since explicitly specifying the template
argument Type should suppress template argument deduction and therefore SFINAE.
But this is irrelevant for a broken-compiler workaround.

2. It's necessary to verify that the main template parameter Type is a class
type before using the expression char (Type::*)(int, float) as a template
parameter. But this is easy using is_class.

Thanks again,

Boost list run by bdawes at, gregod at, cpdaniel at, john at