Note about variant

Mariusz Gliwiński alienballance at gmail.com
Sun Oct 9 01:22:49 PDT 2011


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

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

<code>
import std.variant;

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

void main() {
	Variant(S(1));
}
</code>
<compilation>
/usr/include/d/std/variant.d(538): Error: constructor test.S.this (ubyte b) is 
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 sending it 
via std.concurrency

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

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

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

Regards,
Mariusz Gliwiński


More information about the Digitalmars-d mailing list