Adding the ?. null verification

Etienne via Digitalmars-d digitalmars-d at puremagic.com
Thu Jun 19 13:29:12 PDT 2014


On 2014-06-19 3:11 PM, H. S. Teoh via Digitalmars-d wrote:
>
> 	safeDeref(obj).subobj.prop.field.failsafe!val(defaultVal)
>
> where the last element is passed as an alias to the failsafe template,
> which then does the .init-replacement magic. It looks a lot uglier,
> though. :-(
>
>
> T
>

meh, this works:


writeln(currAssignment.safeDeref.typeInfo.ident.or("meh"));

..
	static struct SafeDeref {
		T t;
		
		// Make the wrapper as transparent as possible.
		alias t this;

		// this overrides if null
		T or(T defVal){
			if (t is t.init)
			{
				return defVal;
			}
			else
			{
				return t;
			}
			
		}
..


More information about the Digitalmars-d mailing list