Why are static arrays not ranges?
anonymous via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Sep 21 13:39:00 PDT 2015
On Monday 21 September 2015 22:33, Jack Stouffer wrote:
> import std.range;
>
> void main() {
> int[6] a = [1, 2, 3, 4, 5, 6];
>
> pragma(msg, isInputRange!(typeof(a)));
> pragma(msg, isForwardRange!(typeof(a)));
> pragma(msg, isRandomAccessRange!(typeof(a)));
> }
>
> $ dmd -run test.d
> false
> false
> false
>
> That's ridiculous. Do I have to wrap my static arrays in structs
> to get range primitives?
You can just slice them: `a[]` is an `int[]` which is a range.
> Is there an actual reason for this?
How would popFront work on an `int[6]`? popFront can't change the type, but
it must remove an element.
More information about the Digitalmars-d-learn
mailing list