Boost logo

Boost :

Subject: Re: [boost] [type_traits] adding is_less_comparable<T>, etc.
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-09-01 11:05:55


Frédéric Bron wrote:
> Here, I cannot find a way to get the return type of operator<(T, U).
> The only thing I can do is:
> 1. do not treat "void operator<(T, U)"
> => thus using is_less_comparable<T, U> if operator<(T, U) returns
> void will be a compilation error
> => no compiler warning for the ternary operator, trick
> 2. treat "void operator<(T, U)"
> => must use the ternary operator, trick => compiler warning
> => is_less_comparable<T, U> is true_type if operator<(T, U) exists
> and returns void (no compiler error)
> I am in favour of solution 1 because when we need
> is_less_comparable<T, U> it is obviously to later do something like
> "bool result=t<u". Then with solution 1 the compilation error would
> come when is_less_comparable<T, U> is invoked and with solution 2 it
> would come when t<u is invoked. So in either case, there will be a
> compilation error somewhere.
> Other issue: I do not see how I can test the return type of operator<
> to check if it is convertible to bool.

Once you know that operator< exists and returns non-void, you can
use simple overload resolution.

typedef char no;
struct yes { no dummy[2]; };

yes is_bool(bool);
no is_bool(...);

sizeof(is_bool(T() < U())) == sizeof(yes);

In Christ,
Steven Watanabe

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