static opSlice is not possible

Alex sascha.orlov at gmail.com
Fri Feb 16 14:41:05 UTC 2018


On Friday, 16 February 2018 at 13:35:03 UTC, Basile B. wrote:
>
> Technically iy's a multi dimensional slicing but there's a 
> constraint on the number of dimension allowed so that it looks 
> exactly like a normal opSlice.
>
> By the way, i reduced too much. This shows more how it works:
>
> struct Foo
> {
>     static auto opSlice(int index)(size_t lo, size_t hi)
>     if (index == 0)
>     {
>         return 41;
>     }
>     static auto opIndex(A...)(A a)
>     {
>         return opSlice!0(0,0) + 1;
>     }
> }
>
> static assert(Foo[0..1337] == 42);

Hey, cool!
Thanks :)


More information about the Digitalmars-d-learn mailing list