
Hi, ----- Original Message ----- From: "Frédéric Bron" <frederic.bron@m4x.org> To: <boost@lists.boost.org> Sent: Tuesday, September 01, 2009 9:38 PM Subject: Re: [boost] [type_traits] adding is_less_comparable<T>, etc.
// two check overloads help us identify which comparison operator was picked
// check(not convertible to bool) returns a reference to char[2] (sizeof>1) template <typename T> char (& check(T))[2] ;
// check(convertible to bool) returns char (sizeof==1) template <typename T> char check(T*) ; char check(bool) ; char check(char) ; char check(signed char) ; char check(unsigned char) ; char check(short) ; char check(unsigned short) ; char check(int) ; char check(unsigned int) ; char check(long) ; char check(unsigned long) ;
template < typename T, typename U > struct is_less_comparable_impl { static typename boost::remove_cv<T>::type &t ; static typename boost::remove_cv<U>::type &u ; static const bool value = sizeof(check(t<u))==1 ;
As sugested by Steven and Robert, have you tried typedef char no; struct yes { no dummy[2]; }; yes is_bool(bool); no is_bool(...); template < typename T, typename U > struct is_less_comparable_impl { static typename boost::remove_cv<T>::type &t ; static typename boost::remove_cv<U>::type &u ; static const bool value = sizeof(is_bool(t<u))==sizeof(yes) ; } instead of
// two check overloads help us identify which comparison operator was picked
// check(not convertible to bool) returns a reference to char[2] (sizeof>1) template <typename T> char (& check(T))[2] ;
// check(convertible to bool) returns char (sizeof==1) template <typename T> char check(T*) ; char check(bool) ; char check(char) ; char check(signed char) ; char check(unsigned char) ; char check(short) ; char check(unsigned short) ; char check(int) ; char check(unsigned int) ; char check(long) ; char check(unsigned long) ;
template < typename T, typename U > struct is_less_comparable_impl { static typename boost::remove_cv<T>::type &t ; static typename boost::remove_cv<U>::type &u ; static const bool value = sizeof(check(t<u))==1 ;
Best, Vicente