On Thursday, 5 September 2019 at 08:16:08 UTC, Daniel Kozak wrote:
in this case you can just use:

auto q = cast()p.x;

Ahh, great! :-)

But that directly gets me to the next question:

import std.stdio;

void main()
{
    Point[] q = [Point(1),Point(3),Point(2)];

    import std.algorithm.searching: minElement;
    writeln(q.minElement!(a=>a.x).x);
}

struct Point
{
   @property immutable long x;
}

This doesn't compile:

/usr/include/dmd/phobos/std/algorithm/searching.d(1365): Error: cannot modify struct extremeElement Point with immutable members /usr/include/dmd/phobos/std/algorithm/searching.d(1307): Error: template instance `test.main.extremum!(__lambda1, "a < b", Point[], Point)` error instantiating /usr/include/dmd/phobos/std/algorithm/searching.d(3445): instantiated from here: extremum!(__lambda1, "a < b", Point[]) test.d(8): instantiated from here: minElement!((a) => a.x, Point[])

Any idea, how to get around this?

Reply via email to