Optional

Optional type. Also known as a Maybe or Option type in some languages.

This can either contain a value or be none. If the value is a refernce type then null is considered none.

It also has range like behavior. So this acts as a range that contains 1 element or is empty.

And all operations that can be performed on a T can also be performed on an Optional!T. The behavior of applying an operation on a no-value or null pointer is well defined and safe.

Constructors

this
this(T value)
this(None )

Constructs an Optional!T value by assigning T

Members

Functions

opAssign
auto ref opAssign(None )
auto ref opAssign(U lhs)
auto ref opAssign(Optional!U lhs)

Assigns a value to the optional or sets it to none.

opBinary
auto opBinary(U rhs)

If the optional is some value it returns an optional of some value op rhs

opBinaryRight
auto opBinaryRight(U lhs)

If the optional is some value it returns an optional of some lhs op value

opCall
auto opCall(Args args)

If there's a value that's callable it will be called else it's a noop

opDollar
auto opDollar()

Provides indexing into arrays

opEquals
bool opEquals(None )
bool opEquals(Optional!U rhs)
bool opEquals(U rhs)
bool opEquals(R other)

Compare two optionals or an optional with some value

opIndex
auto opIndex(size_t index)
auto opIndex()

Provides indexing into arrays

opOpAssign
auto opOpAssign(U rhs)

If the optional is some value, op assigns rhs to it

opSlice
auto opSlice(size_t begin, size_t end)

Provides indexing into arrays

opUnary
auto opUnary()

Applies unary operator to internal value of optional.

popFront
void popFront()
Undocumented in source. Be warned that the author may not have intended to support it.
toRepresentation
Json toRepresentation()
Undocumented in source. Be warned that the author may not have intended to support it.
toString
string toString()

Converts value to string

Properties

empty
bool empty [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
front
inout(T) front [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.

Static functions

fromRepresentation
Optional!T fromRepresentation(Json value)
Undocumented in source. Be warned that the author may not have intended to support it.

Meta