Re: has_foo revisited...
In article <1146493260.632850.19690@g10g2000cwb.googlegroups.com>,
<rune.sune@yahoo.com> wrote:
struct has_foo
{
typedef char One;
typedef struct { char tmp[2]; } Two;
typedef int (T::*PMF)() const;
template <PMF> struct wrapper;
template <typename U>
static One test(U*, wrapper<&U::foo>* = 0); // why these two params?
static Two test(...);
enum { value = (1 == sizeof(has_foo<T>::test((T*)0)))};
};
so that
struct is_false {int a;};
struct is_true {void foo() {}};
has_foo<is_false> which does not have a member foo selects the
ellipsised function since is_false::foo does not exist and
&is_false::foo is a syntax failure so the only candidate is test(...)
where &is_true::foo is valid syntax and thus test(is_true *,
&is_true::foo) is a better match than test(...) and test(is_true *,
&is_true::foo) is chosen.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]