Structs are Not Plain: A call for empty struct constructors
Max Samukha
maxsamukha at gmail.com
Thu Sep 19 10:34:31 UTC 2019
On Thursday, 19 September 2019 at 09:30:00 UTC, Nicholas Wilson
wrote:
> A workaround, wrap it with alias this in another struct:
>
> ```
> import std.stdio;
> struct Foo
> {
> int a;
> this(int) { a = -1; }
> ~this() { writeln("~this(), a = ",a); }
> }
>
> struct Bar
> {
> Foo f = Foo(1);
> alias f this;
> }
> void main()
> {
> with(Bar())
> {
> writeln(a);
> a = 42;
> }
> }
> ```
Won't work - Foo(1) is evaluated at compile time.
More information about the Digitalmars-d
mailing list