alias O = Optional!int; assert(O.some(3) == Some!int(3)); assert(O.none() == None()); assert(O.some(3).match!( (None _) => false, // use Some/None to match (int) => true, // or use the underlying type to match )); assert(O.init == O.init); assert(O.some(0) != O.none()); static assert(!__traits(compiles, O.init = Some!(Some!int).init)); static assert(!__traits(compiles, Optional!O.init = Some!int.init)); static assert(!__traits(compiles, O.init = Some!short.init)); // TODO: should this be allowed? static assert(!__traits(compiles, O.some(none))); static assert( __traits(compiles, Optional!O.some(none))); static assert( __traits(compiles, Optional!(Optional!O).some(none.some))); static assert( __traits(compiles, Optional!(Optional!O).some(10.some.some))); static assert(!__traits(compiles, Optional!(Optional!O).some(10.some.some.some))); static assert(!__traits(compiles, Optional!(Optional!O).some(10.some))); () @trusted { assert((O.some(3) = 10.some) == 10.some); assert((O.some(3) = none) == none); } ();