Movatterモバイル変換


[0]ホーム

URL:


D Logo
Menu
Search

Library Reference

version 2.112.0

overview

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 usinga local clone.

dmd.root.optional

Implementation of an 'Optional' type
Authors:
Walter Bright
License:
Boost License 1.0

Sourceroot/optional.d

Documentationhttps://dlang.org/phobos/dmd_root_optional.html

Coveragehttps://codecov.io/gh/dlang/dmd/src/master/compiler/src/dmd/root/optional.d

Examples:
import core.exception : AssertError;Optional!int opt;assert( opt.isEmpty());assert(!opt.isPresent());assert(!opt.hasValue(1));assert(!opt.hasValue(2));bool caught;trycast(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 eitherempty or contains a value of typeT
this(Tvalue);

static Optional!Tcreate(Tval);
Creates anOptional with the given value
boolisPresent() const;
Returns:
Whether thisOptional contains a value
boolisEmpty() const;
Returns:
Whether thisOptional does not contain a value
inout(T)get() inout;
Returns:
The value if present
boolhasValue(const Texp) const;
Returns:
Whether thisOptional contains the supplied value
Copyright © 1999-2026 by theD Language Foundation | Page generated byDdoc on Fri Feb 20 17:56:13 2026

[8]ページ先頭

©2009-2026 Movatter.jp