Report a bug
		
				If you spot a problem with this page, click here to create a Bugzilla issue.
		
			Improve this page
		
			Quickly fork, edit online, and submit a pull request for this page.
			Requires a signed-in GitHub account. This works well for small changes.
			If you'd like to make larger changes you may want to consider using
			a local clone.
		
	dmd.root.optional
Implementation of an 'Optional' type
Authors: 
License: 
Source root/optional.d
Documentation https://dlang.org/phobos/dmd_root_optional.html
Examples: 
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));
- structOptional(T);
- Optional type that is either empty or contains a value of type T- this(Tvalue);
 static Optional!Tcreate(Tval);
- Creates an Optional with the given value
- boolisPresent() const;
- Returns:Whether this Optional contains a value
- boolisEmpty() const;
- Returns:Whether this Optional does not contain a value
- inout(T)get() inout;
- Returns:The value if present
- boolhasValue(const Texp) const;
- Returns:Whether this Optional contains the supplied value
 
Copyright © 1999-2025 by the D Language Foundation | Page generated by
Ddoc on Mon Mar 31 10:27:38 2025