Boost logo

Boost :

Subject: Re: [boost] review request: addition to type_traits library of is_less_comparable<T, U> and others
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-10-09 12:24:53

Frédéric Bron wrote:
> > Is it reasonable to additionally verify the returned type?
> > IMO, such kind of
> > traits should not make assumptions about the operators
> > meaning, they should
> > merely show whether the comparison expression is valid.
> > Thus there also
> > should not be a fails-to-compile case.
> OK, what do you know if you know that you can write t<u but do not
> know if it is convertible to bool?
> You know that "t<u ;" is OK but maybe "if (t<u) ..." will not work ->
> compile time error.
> I think that in most cases you want to know that it behaves like
> operator< used with built-in types.

I think the tribool example -- and other UDTs with Boolean-plus behavior -- is a great example for not assuming convertible-to-bool is the only behavior to support.

> I agree that it is not "nice" to have a compile time error when used
> with operator< returning void but I prefer that than returning true
> because this behaviour is not the one expected by operator<. If
> anybody has a solution on how to return false in such case...

It may be that being able to examine the return type -- we never did anything to make that work, did we? -- of the various operators would leave the answer to that question to the caller. For example, if < returns void, but > returns something convertible to bool, generic code could use > instead of < for sorting. (Far fetched, to be sure, but the idea, in general, seems reasonable.)

I also agree with the idea of providing a "normal" case of "is t < u usable in a Boolean context?"

Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

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