handful and interval

David Piepgrass qwertie256 at gmail.com
Mon Sep 3 08:50:50 PDT 2012


>>>> if (a.among("struct", "class", "union")) { ... }
>>>> if (b.between(1, 100)) { ... }
>>>
>>> Is between inclusive or not of the endpoints?
>>
>> After quite a bit of thought, I think inclusive is the right 
>> way.
>
> Then there's no way to specify an empty interval. I suppose 
> with "between" that would not be relevant.

Perhaps b.between(1, 0) would always return false.

However I'd use different names: among=>isOneOf, 
between=>isInRange. I would also define another function inRange 
that ensures, rather than tests, that a value is in range:

string userInput = "-7";
int cleanInput = inRange(parse!int(userInput), 1, 100);


More information about the Digitalmars-d mailing list