Allowing Expressions such as (low < value < high)

Dejan Lekic via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Sep 9 01:50:49 PDT 2014


On Thursday, 4 September 2014 at 20:03:57 UTC, Nordlöw wrote:
> Are there any programming languages that extend the behaviour 
> of comparison operators to allow expressions such as
>
>     if (low < value < high)
>
> ?
>
> This syntax is currently disallowed by DMD.
>
> I'm aware of the risk of a programmer misinterpreting this as
>
>     if ((low < value) < high)

It is not just that... Imagine this (nothing prevents you from 
doing it):

    if (foo < bar < baz < trt < mrt < frt /* etc */) {}


More information about the Digitalmars-d-learn mailing list