Optional

Undocumented in source.

Alias This

st

Members

Aliases

None
alias None = .None
Undocumented in source.
Some
alias Some = .Some!T
Undocumented in source.
back
alias back = front
Undocumented in source.
empty
alias empty = isNone
Undocumented in source.
length
alias length = isSome
Undocumented in source.
opDollar
alias opDollar(size_t dim : 0) = length
Undocumented in source.
popBack
alias popBack = popFront
Undocumented in source.

Functions

front
inout(T) front()
Undocumented in source. Be warned that the author may not have intended to support it.
isNone
bool isNone()
Undocumented in source. Be warned that the author may not have intended to support it.
isSome
bool isSome()
Undocumented in source. Be warned that the author may not have intended to support it.
opAssign
auto ref opAssign(U rhs)
Undocumented in source. Be warned that the author may not have intended to support it.
opAssign
auto ref opAssign(None )
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(Optional rhs)
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(None _)
Undocumented in source. Be warned that the author may not have intended to support it.
opEquals
bool opEquals(U rhs)
Undocumented in source. Be warned that the author may not have intended to support it.
opIndex
ref opIndex()
Undocumented in source. Be warned that the author may not have intended to support it.
opIndex
inout(T) opIndex(size_t index)
Undocumented in source. Be warned that the author may not have intended to support it.
opIndex
ref opIndex(size_t[2] dim)
Undocumented in source. Be warned that the author may not have intended to support it.
opSlice
size_t[2] opSlice(size_t start, size_t end)
Undocumented in source. Be warned that the author may not have intended to support it.
popFront
void popFront()
Undocumented in source. Be warned that the author may not have intended to support it.
save
inout(Optional) save()
Undocumented in source. Be warned that the author may not have intended to support it.

Static functions

none
none()
Undocumented in source. Be warned that the author may not have intended to support it.
some
some(U s)
Undocumented in source. Be warned that the author may not have intended to support it.
some
some(None )
Undocumented in source. Be warned that the author may not have intended to support it.

Variables

st
SumType!(Some, None) st;
Undocumented in source.

Examples

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);
}
();

Meta