The optional itself
the value type
the Throwable to be called when get() is called and no value is present
Creating an Optional!(T) with no value present and then trying to get the value, which results in an exception
struct MyType { } Optional!(MyType) d; assert(d.isPresent() == false); assert(d.isEmpty()); d = Optional!(MyType)(); assert(d.isPresent() == false); assert(d.isEmpty()); d = Optional!(MyType).empty(); assert(d.isPresent() == false); assert(d.isEmpty()); try { d.get(); assert(false); } catch(OptionalException) { assert(true); }
Creating an Optional!(T) with a value present and then trying to get the value, which results in said value being returned
Optional!(byte) f = Optional!(byte)(1); assert(f.isPresent() == true); assert(f.isEmpty() == false); try { assert(1 == f.get()); } catch(OptionalException) { assert(false); }
Optionals for a given type and with a customizable exception to be thrown when a value is not present and get() is called.