Boost logo

Boost :

Subject: Re: [boost] Interest in chained relational operations
From: Joaquin M López Muñoz (joaquinlopezmunoz_at_[hidden])
Date: 2016-10-22 04:53:18


El 21/10/2016 a las 23:43, Rahman Salim Zengin escribió:
> Hi,
>
> The code in question is a simple chained comparison implementation. It
> works with any type If relational operators for that type is defined.
>
> https://github.com/rszengin/chain
>
> May some people find it useful?

I think this can be further evolved to be useful. A couple of comments:

* Seconding Edward's answer, using operator < to initiate the comparison
chain

   cmp::chain < 0 < x <= 5

looks arbitrary. Maybe operator <<

   cmp::chain << 0 < x <= 5

or something even less smart

   cmp::chain{0} < x <= 5

is better.

* As it stands, you're not detecting foul-smelling comparisons such as

   cmp::chain < x <= y >= z // not exactly wrong, but not the
mathematical custom

or (more importantly)

   cmp::chain < 5 <= y <= 0 // always false

The first can be made not to compile by making Comparator::operator<
(and <=) return a type different than and incompatible with the type
returned by
Comparator::operator> (and >=). As for the second I *think* it can be
detected
with some constexpr machinery.

Joaquín M López Muñoz


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