Boost logo

Boost :

Subject: Re: [boost] review request: addition to type_traits library of is_less_comparable<T, U> and others
From: Seth Bunce (seth_at_[hidden])
Date: 2009-10-08 17:37:42


On Thu, 8 Oct 2009 08:44:09 +0200
Frédéric Bron <frederic.bron_at_[hidden]> wrote:

> I would like to propose to your review the following addition to the
> type_traits library (at
> https://svn.boost.org/trac/boost/browser/sandbox/type_traits
> and http://dl.free.fr/tK0BwIzYy).
>
> The purpose of the addition is to add type traits to detect if types T and U
> are comparable in the sens of <, <=, >, >=, == or != operators, i.e. if
> t<u has a sens when t is of type T and u of type U (same for <=, >, >=, ==,
> !=).
>
> The following traits are added:
>
> is_equal_to_comparable<T,U>
> is_greater_comparable<T,U>
> is_greater_equal_comparable<T,U>
> is_less_comparable<T,U>
> is_less_equal_comparable<T,U>
> is_not_equal_to_comparable<T,U>
>
> The names are based on the corresponding names of the standard
> template library (<functional> header, section 20.3.3 of the
> standard).
>
> The code has the following properties:
> * returns true if t<u is meaningful and returns a value convertible to bool
> * returns false if t<u is meaningless.
> * fails with compile time error if t<u is meaningful and returns void
> (a possibility to avoid compile time error would be to return true
> with an operator, trick but this has little sens as returning false
> would be better)
>
> The compilation has been tested with g++ 4.3.2 and icpc 10.0 on linux
> 64 bits, g++ 3.4.4 on cygwin, mingw32 3.4.4 on cygwin.
>
> Regards,
>
> Frédéric

Is there some practical advantage to having type traits for all of these operators?

"<=, >, >=, ==, and !=" can all be expressed in terms of "<".

It seems like if all of the operators are supported it will encourage boost developers to move complexity from the back end (what boost developers see) to the front end (what users see).

If a boost developer requires a user defined type to specify more than "<" for the purpose of doing any of "<, <=, >, >=, ==, and !=", it effectively moves complexity to the front end.

        -Seth


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