On Monday, 30 January 2017 at 10:45:03 UTC, cym13 wrote:

Meh.

Forget that, bad memory. remove isn't working in-place. However slapping ".array" is still asking explicitely for reallocation, so just forget it. Here is a code that works:

import std.conv;
import std.stdio;
import std.format;
import std.algorithm;

void main(string[] args) {
    int [] arr = [8, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];

    auto before = arr.ptr;
    arr = arr.remove!(x => x>5);
    auto after  = arr.ptr;

    assert(arr == [0, 1, 2, 3, 4, 5], arr.to!string);
    assert(before == after, "%s %s".format(before, after));
}

OK, got it. Can you do removal without reallocation with std.container.array?

    Array!int arr;
    foreach (i; 0..10) arr ~= i;




Reply via email to