www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: [GSOC] Database API

reply Kagamin <spam here.lot> writes:
Kagamin Wrote:

 Kagamin Wrote:
 
 Robert Jacques Wrote:
 
 Should be Algebraic!(T, void). If that doesn't currently compile, we  
 should make it compile.

 Andrei

For what it's worth, both Algebraic!(T, void*) and Algebraic!(T, void) compile on my branch of std.variant.

can't assign null alias Algebraic!(int,void) nint; nint n1=5; assert(n1==5); n1=null; \std\variant.d:497: Error: static assert "Cannot store a void* in a VariantN!(maxSize,int,void). Valid types are (int, void)" test.d:45: instantiated from here: opAssign!(void*)

Ahh, there's a workaround: alias Algebraic!(int,void) nint; nint n1=5; assert(n1.get!(int)==5); n1=nint(); //uninitialized Variant, sort of null assert(!n1.hasValue); assert(n1.peek!(int)==null); writeln("error here:"); assert(n1.get!(int)==0);

this also works without allowing void! alias Algebraic!(int) nint; nint n1=5; assert(n1.get!(int)==5); n1=nint(); //still null assert(!n1.hasValue); assert(n1.peek!(int)==null); writeln("error:"); assert(n1.get!(int)==0);
Mar 26 2011
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 3/26/11 5:33 PM, Kagamin wrote:
 Kagamin Wrote:

 Kagamin Wrote:

 Robert Jacques Wrote:

 Should be Algebraic!(T, void). If that doesn't currently compile, we
 should make it compile.

 Andrei

For what it's worth, both Algebraic!(T, void*) and Algebraic!(T, void) compile on my branch of std.variant.

can't assign null alias Algebraic!(int,void) nint; nint n1=5; assert(n1==5); n1=null; \std\variant.d:497: Error: static assert "Cannot store a void* in a VariantN!(maxSize,int,void). Valid types are (int, void)" test.d:45: instantiated from here: opAssign!(void*)

Ahh, there's a workaround: alias Algebraic!(int,void) nint; nint n1=5; assert(n1.get!(int)==5); n1=nint(); //uninitialized Variant, sort of null assert(!n1.hasValue); assert(n1.peek!(int)==null); writeln("error here:"); assert(n1.get!(int)==0);

this also works without allowing void! alias Algebraic!(int) nint; nint n1=5; assert(n1.get!(int)==5); n1=nint(); //still null assert(!n1.hasValue); assert(n1.peek!(int)==null); writeln("error:"); assert(n1.get!(int)==0);

Awesome. Talk about forgetting my own code :o). Andrei
Mar 26 2011