Getting NotNull Right

Adam D. Ruppe destructionator at gmail.com
Wed Feb 5 13:32:35 PST 2014


The alias this could be changed to allow conversion to the base 
class one step at a time. I'm not happy with it since it'd 
essentially do a big chain down to Object and it also ignores 
interfaces, but it's a start:

     static if(is(T == class) && !is(T == Object))
     @property NotNull!(BaseClassesTuple!T[0]) _valueHelper() inout
     {
         assert(_value !is null); // sanity check of invariant
         return assumeNotNull(cast(BaseClassesTuple!T[0]) _value);
     }
     else
     @property inout(T) _valueHelper() inout
     {
         assert(_value !is null); // sanity check of invariant
         return _value;
     }


(Previously, it just had the second _valueHelper)


More information about the Digitalmars-d-learn mailing list