Optional type that is either empty or contains a value of type T
import core.exception : AssertError; Optional!int opt; assert( opt.isEmpty()); assert(!opt.isPresent()); assert(!opt.hasValue(1)); assert(!opt.hasValue(2)); bool caught; try cast(void) opt.get(); catch (AssertError) caught = true; assert(caught); opt = Optional!int(1); assert(!opt.isEmpty()); assert( opt.isPresent()); assert( opt.get() == 1); assert( opt.hasValue(1)); assert(!opt.hasValue(2));
Copyright (C) 1999-2023 by The D Language Foundation, All Rights Reserved
Implementation of an 'Optional' type