$, __dollar, opDollar: can't define my own?
Fredrik Olsson
peylow at gmail.com
Wed Oct 4 23:31:27 PDT 2006
Oskar Linde skrev:
<snip>
> This may all be a bit overkill, but what would be really great is having
> a range type that a..b expands into at lest. That type could then
> support opApply making
>
> foreach(i; 0..10) { ... }
>
> possible for instance.
>
YES! Ranges and sets, as I have pleaded for ages. It is a bliss for
reducing code size, and allows some very nice readability stuff. It is
not that hard to implement either, most Pascal implementations does it
with a simple bit-field.
Doing it with templates and tricks gets you the functionality, but
misses the point of a clean and readable syntax.
// is it lowercase ASCII?
if (ch in 'a'..'z') { ... }
// Is the selection bold?
if (TextAttriibutes.BOLD in text.selection.attributes() { ... }
// Make selected text underline.
text.selection.attributes += TextAttriibutes.UNDERLINE;
// Get all days where both Adam and Beatrice are free, but not monday.
goodDays = adam.availableDays - beatrice.availableDays - Days.MONDAY;
Ranges and sets are priceless for handling "a bag of values", without
the need to write error prone iterations, or just as error prone and
large boolean expressions.
// Fredrik Olsson
More information about the Digitalmars-d
mailing list