Optional

Defines an optional type

Optional values are values that can be or not defined.

Constructors

this
this(T value)

Constructs an optional type with a defined given value

this
this(None )

Constructs an optional type with a non defined value

Destructor

~this
~this()

Distructs the optional object

Members

Functions

opAssign
auto ref opAssign(None )

Assign this optional to a none

opAssign
auto ref opAssign(U lhs)

Assign this optional to a value

opAssign
auto ref opAssign(Optional!U lhs)

Assign this optional to another optional

opBinary
auto opBinary(U rhs)

Binary operator with auto return types

opBinaryRight
auto opBinaryRight(U lhs)

Binary operator with auto return types

opCall
auto opCall(Args args)

Call operator with auto return types

opDollar
auto opDollar()

Dollar operator representing the length of the array

opEquals
bool opEquals(None )

Compares this optional with an empty None value

opEquals
bool opEquals(Optional!U rhs)

Compares this optional with another optional for equality

opEquals
bool opEquals(Nullable!U rhs)

Compares this optional with a nullable for equality

opEquals
bool opEquals(U rhs)

Compares this optional with a value for equality

opEquals
bool opEquals(R rhs)

Compare this optional with an input range for equality

opIndex
auto opIndex(size_t index)

Index operator with auto return types

opIndex
auto opIndex()

Index operator with auto return types

opOpAssign
auto opOpAssign(U rhs)

Op Assign operator with auto return types

opSlice
auto opSlice(size_t begin, size_t end)

Slice operator with auto return types

opUnary
auto opUnary()

Unary operator with auto return type

popFront
void popFront()

Mark this optional as undefined

toHash
size_t toHash()

Calculates the hash value of the value inside this optional

toString
string toString()

Convert the optional to a human readable string.

Properties

defined
bool defined [@property getter]

Check if the optional type is defined

empty
bool empty [@property getter]

Check if the optional type is empty

front
inout(T) front [@property getter]
get
inout(T) get [@property getter]

Attemp to get the defined value

getOr
inout(T) getOr [@property setter]
inout(U) getOr [@property setter]

Gets the optional value or fallback if no value defined

Examples

Optional!int foo; // undefined
foo = 7; // now its defined to 7

// can also be undefined again
foo.popFront();

Meta