[Issue 19631] Segfault on simple nested templated struct
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jan 30 20:43:05 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=19631
--- Comment #3 from Arne Marschall <bestellung at marschall-informatik.de> ---
(In reply to Basile-z from comment #2)
> Problem happens when the initializer type is being determined.
> In case of this issue is blocking some work there are two possible
> workarounds in addition to the "non nesting" solution.
>
> 1. Field!(w, h) a = *new Field!(w, h);
> 2. bool[_h][_w] s = void;
Actually this is not a blocker, I am only training myself. So I ported this
"Game of Life" example and experimented with different arrays. The templated
version crashed it.
This would work as well
Field!(w, h) a;
But the complete code uses two instances of Field, a & b and swaps them a lot.
Swapping of a and b is done much faster if they are pointers instead of 100x100
arrays.
This version compiles as well and takes advantage of the internal pointers
within dynamic arrays.
auto ab = [Field!(w, h).init, Field!(w, h).init];
instead of a and b it uses ab[0] and ab ab[1].
And swaps them here.
import std.algorithm.mutation : swap;
swap(ab[0], ab[1]);
--
More information about the Digitalmars-d-bugs
mailing list