[Issue 5395] Interval literals

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Feb 12 14:55:50 PST 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5395



--- Comment #5 from bearophile_hugs at eml.cc 2011-02-12 14:53:19 PST ---
Peter Alexander:

> auto foo = [ 1..10 : 2, 2..20 : 3 ];
>
> Is foo an AA of ranges to ints, or an array of stepped ranges?

Lazy strided intervals as associative array keys is not a common need. But
there are few other situations:
auto r = pred ? 1..10 : 2 : 2..20 : 3;

Where the range syntax is not usable you may use the function from Phobos as
fall-back:
auto r = pred ? iota(1,10,2) : iota(2,20,3);

A possible alternative is to require parentheses where the syntax is ambiguous:
auto foo = [(1..10 : 2), (2..20 : 3)];
auto r = pred ? (1..10 : 2) : (2..20 : 3);

Another alternative is to use .. to separate the stride too:
auto foo = [1..10..2, 2..20..3];
auto r = pred ? 1..10..2 : 2..20..3;

Here I assume that the interval syntax is usable on integral values only, like
ints, uints, chars, wchars, BigInts, etc. For floating point values you use
iota again:
iota(1.0, 10.0, 0.5)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list