www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Note about variant

Firstly, i don't know if i'm using latest version (this is from dmd 2.0=
55).
Ok now, generally - i love it, BUT today it tortured me :(.

Firstly, it should be checked if argument struct has copy constructor (=
or how=20
i should name it):

<code>
import std.variant;

struct S {
=09ubyte b;
=09ubyte[32] garbage;
=09
=09this(ubyte b) {
=09=09this.b =3D b;
=09}
=09
=09//this(S r) {} // it needs to be uncommented
}

void main() {
=09Variant(S(1));
}
</code>
<compilation>
/usr/include/d/std/variant.d(538): Error: constructor test.S.this (ubyt=
e b) is=20
not callable using argument types ()
/usr/include/d/std/variant.d(538): Error: expected 1 function arguments=
, not 0
</compilation>

Secondly, even if you've defined it, you might have problems with sendi=
ng it=20
via std.concurrency

<code>
import std.variant,
=09std.concurrency;

struct S {
=09ubyte[33] garbage;
=09
=09this(ubyte size) {}
=09
=09this(S n) {}
}

void main() {
=09send(thisTid, Variant(S(1)));
}
</code>
<runtime>
core.exception.AssertError /usr/include/d/std/variant.d(279): target mu=
st be=20
non-null
<runtime>

Regards,
Mariusz Gliwi=C5=84ski
Oct 09 2011