another cool RTInfo trick - i want in runtime

Adam D. Ruppe destructionator at gmail.com
Fri Jan 17 04:40:05 PST 2014


On Friday, 17 January 2014 at 07:35:00 UTC, Marco Leise wrote:
> void foo(Object o) {
>     if (o !is null) {
>         bar(o);
>     }
> }

My current NotNull draft allows this:
http://arsdnet.net/dcode/notnull.d

	int b;
	int* bp = &b;
	if(auto a = bp.checkNull) {
		static assert(is(typeof(a == NotNull!(int*))));
	} else {
		assert(0);
	}

So the type of bp doesn't change like it might when built into 
the language but since we can do if(auto a = ...) it is pretty 
close.

Thanks to Andrej Mitrovic for the checkNull code.


More information about the Digitalmars-d mailing list