|
Boost : |
Subject: Re: [boost] SFINAE yes_type and no_type
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2011-04-16 07:02:14
On 16/04/2011 12:45, Mathias Gaunard wrote:
> On 16/04/2011 12:32, Robert Jones wrote:
>> On Sat, Apr 16, 2011 at 11:23 AM, Mathias Gaunard<
>> mathias.gaunard_at_[hidden]> wrote:
>>
>>>
>>> They need to be differently sized types so that you can use sizeof to
>>> distinguish which function overloads gets picked up.
>>>
>>>
>> I didn't understand that at all, quite possibly because I
>> misunderstood the
>> OP. What overloads are we seeking
>> to distinguish? (Sorry if I'm being a bit slow here!)
>
> SFINAE is usually used to define traits like this:
>
> template<typename T>
> struct my_trait
> {
> typedef char yes_type;
> struct no_type
> {
> char dummy[2];
> };
>
> template<typename X>
> yes_type test(whatever_you_want_to_test_with_X *);
>
> no_type test(...);
sorry, forgot a template<typename X> over the second overload there.
>
> static const bool value = sizeof(test<T>(0)) == sizeof(yes_type);
> typedef boost::mpl::bool_<value> type;
> };
>
> _______________________________________________
> 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