Optional

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

This can either contain a value or be none. It works with any value, including values that can be null. I.e. null is a valid value that can be contained inside an optional if T is a pointer type

It also has range like behavior. So this acts as a range that contains 1 element or is empty. Similar to std.algorithm.only

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(U value)
this(None )

Constructs an Optional!T value by assigning T

Members

Functions

opAssign
void opAssign(None )
void opAssign(U lhs)
void opAssign(Optional!U lhs)

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

opBinary
auto ref opBinary(U rhs)

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

opBinaryRight
auto ref opBinaryRight(U lhs)

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

opCall
auto ref opCall(Args args)

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

opDollar
auto opDollar()

Ditto Ditto

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 ref opIndex()

Provides indexing into arrays

opOpAssign
auto ref opOpAssign(U rhs)

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

opUnary
auto ref 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.

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

construct
Optional!T construct(Args args)

Allows you to create an Optional type in place.

Meta