Boost logo

Boost :

Subject: Re: [boost] SFINAE yes_type and no_type
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2011-04-16 06:45:43

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(...);

     static const bool value = sizeof(test<T>(0)) == sizeof(yes_type);
     typedef boost::mpl::bool_<value> type;

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