Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2002-03-22 10:00:12

Jason Shirk wrote:
> I don't think this would be conforming, defaults are not part of the
> function type, so the rules of 14.8.2/2 don't help.
> But if you used something like:
> template < typename T, void (T::*)() > struct ptmf_helper {};
> template< typename T >
> yes_tag has_member_foo_helper(int, ptmf_helper<T, &T::foo>* p = 0);
> Then I think this could work.

It works! (with Comeau C/C++, and as far as I can see it's

    typedef char (&no_tag)[1];
    typedef char (&yes_tag)[2];

    template < typename T, void (T::*)() > struct ptmf_helper {};
    template< typename T > no_tag has_member_foo_helper(...);

    template< typename T >
    yes_tag has_member_foo_helper(ptmf_helper<T, &T::foo>* p);

    template< typename T >
    struct has_member_foo
            , value = sizeof(has_member_foo_helper<T>(0)) == sizeof(yes_tag)

    struct my {};
    struct her { void foo(); };


Jason, you're a genius!

> Oddly enough, the rules in 14.8.2/2 don't mention this case as one of
> the possible failures. If the standard is going to the trouble of
> enumerating everything that will fail, then this case should certainly
> be included.
> Now if only VC7.1 could compile that...

I _really_ wish it could :).


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