Boost logo

Boost :

From: Jason Shirk (jasonsh_at_[hidden])
Date: 2002-03-22 03:35:01


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.

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...

Jason Shirk
VC++ Compiler Team

> -----Original Message-----
> From: Aleksey Gurtovoy [mailto:agurtovoy_at_[hidden]]
> Sent: Thursday, March 21, 2002 11:37 PM
> To: boost_at_[hidden]
> Subject: [boost] has_member?
>
> Seems that something like the following should give us an ability to
check
> for presence of a particulary named member [function/data] in a class:
>
> typedef char (&no_tag)[1];
> typedef char (&yes_tag)[2];
>
> template< typename T > no_tag has_member_foo_helper(...);
>
> template< typename T >
> yes_tag has_member_foo_helper(int, void (T::*)() = &T::foo);
>
> template< typename T >
> struct has_member_foo
> {
> BOOST_STATIC_CONSTANT(bool
> , value = sizeof(has_member_foo_helper<T>(0)) ==
sizeof(yes_tag)
> );
> };
>
> struct my {};
> struct her { void foo(); };
>
> int main()
> {
> BOOST_STATIC_ASSERT(!has_member_foo<my>::value);
> BOOST_STATIC_ASSERT(has_member_foo<her>::value);
>
> return 0;
> }
>
> /Aleksey
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk