On Tuesday, 23 January 2018 at 14:55:39 UTC, Simen Kjærås wrote:
auto map(alias fn, R)(R r) if (isInputRange!(HeadMutable!R))
{
    // Pass head-mutable versions to MapResult.
    return MapResult!(fn, HeadMutable!R)(headMutable(r));
}

Another thing that I didn't think of when writing the above code was how this works with a mutating lambda:

unittest {
    const a = [1,2,3,4].map!((ref v) => v*=2);
HeadMutable!(typeof(a)) b; // static assert "No head-mutable type for const(MapResult!(__lambda1, int[]))"
}

Which makes sense - there is no way to make a head-mutable version of a from itself - it would break the constness guarantees.

--
  Biotronic

Reply via email to