On 04/22/2014 11:10 AM, H. S. Teoh via Digitalmars-d wrote:

> is there a way to take a slice of the static array, set the
> length to zero,

Currently, instead of setting the length to zero, you should start with the whole slice.

> and append to it with ~=

Instead, you can use the output range primitive put().

> such that when it runs out of space in the static buffer

When slice.empty, it would have covered the static array completely:

import std.range;

void foo()
{
    int[2] buffer;
    int[] slice = buffer[];

    foreach (int i, _; slice) {
        slice.put(i);
    }

    assert(buffer == [ 0, 1 ]);
}

void main()
{
    foo();
}

Ali

Reply via email to