Boost logo

Boost :

Subject: Re: [boost] Interest in chained relational operations
From: Klemens Morgenstern (klemens.morgenstern_at_[hidden])
Date: 2016-10-22 06:01:10

Am 21.10.2016 um 23:43 schrieb Rahman Salim Zengin:
> Hi,
> The code in question is a simple chained comparison implementation. It
> works with any type If relational operators for that type is defined.
> May some people find it useful?
> _______________________________________________
> Unsubscribe & other changes:
Considering that the actual use-cases are things like "x < y <= z" I'd
rather think about this as a set of ternary operators. They would be:

< <
< <=
<= <
<= <=

> >
>= >
> >=
>= >=

Things like x < y > z wouldn't make that sense from a logical point of
view - I'd just not allow them.

I think the right approach would be something like that:

x < ternary(y) < z

That way you can limit the amount of operators available, so what is
writtern there actually makes sense.

I'd actually return bool for the ternary example, but you have one with
five values. I wouldn't do it, but you could let the ternary operation
return a bool-convertible proxy object, so you could chain up five:

0.4 < ternary(a <= ternary(b) <= c) < 0.6

But I'm not sure there are actually that much use cases; I'd think the
main would be, to check if y is in the right range.

And then - to top it off - we could add comparisions with a tolerance
(should work according to the operator precedence rules):

x == y +- ternary(z)

and it could be made a relative tolerance.

x == y +- ~ ternary(z)

Well - those are basically the useful ternary operations I can think of.

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