Boost logo

Boost :

Subject: [boost] [contract] SFINAE question for concepts
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2012-10-03 16:02:29


Hello all,

I have a SFINAE question. The following correctly returns false for
eq1<x>::value when x has no operator==

template< typename T >
struct eq1
{
    T a; T b;
    template< typename TX > static char check ( TX a, TX b, char(*)[sizeof
        (std::is_convertible<decltype(a == b), bool>)
    ]);
    template< typename TX > static long check ( ... );
    static const bool value = sizeof(char) == sizeof check<T>(a, b, 0);
};

However, the following implementation that uses bool{a == b}
incorrectly returns true for eq2<x>::value even if x has no
operator==... why? BTW, if I just use (a == b) instead of bool{a == b}
then it works...

template< typename T >
struct eq2
{
    T a; T b;
    template< typename TX > static char check ( TX a, TX b, char(*)[sizeof
        bool{a == b}
    ]);
    template< typename TX > static long check ( ... );
    static const bool value = sizeof(char) == sizeof check<T>(a, b, 0);
};

A complete example is attached. I'm using clang++ 3.2 with -std=c++0x.

Thanks,
--Lorenzo




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