Allowing Expressions such as (low < value < high)

klpo via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Sep 5 00:26:44 PDT 2014


On Thursday, 4 September 2014 at 20:29:09 UTC, Nordlöw wrote:
> On Thursday, 4 September 2014 at 20:03:57 UTC, Nordlöw wrote:
>>    if (low < value < high)
>
> An alternative could be
>
>     if (value in low..high)
>
> but then the problem would be to remember that this range is 
> actually
>
>     [low..high[
>
> to be compliant with range indexing semantics.
>
> But it could still be a useful a quite self-explanatory syntax.

a similar syntax exists in the Pascal-like langs: for example:

     if not (nbr in [0..9]) then...

Which as no direct equivalent in D, except maybe the "library" 
solution, using std.range.iota + algo.canFind:

     if (!canFind(iota(0, 10, 1), nbr)) ...

The problem is in D "[0..9]" has a completely different 
signification. But this would be a nice syntax.



More information about the Digitalmars-d-learn mailing list