Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions std/typecons.d
Original file line number Diff line number Diff line change
Expand Up @@ -2326,14 +2326,29 @@ string alignForSize(E...)(const char[][] names...)
}

/**
Defines a value paired with a distinctive "null" state that denotes
the absence of a value. If default constructed, a $(D
Nullable!T) object starts in the null state. Assigning it renders it
non-null. Calling $(D nullify) can nullify it again.
Defines a value that can be "nullified". If `T` can already be
"nullified" (i.e. if `T` is a class, interace, pointer, dynamic array)
then it is implemented as an API wrapper adding methods like `isNull`
and `nullify`, otherwise, it adds an extra `bool` field to represent
the "nullified" state.
*/
template Nullable(T)
{
alias Nullable = NullableWithExtraField!T;
}

Practically $(D Nullable!T) stores a $(D T) and a $(D bool).
/**
Defines a value paired with a distinctive "null" state that denotes
the absence of a value. If default constructed, a $(D Nullable!T)
object starts in the null state. Assigning it renders it non-null.
Calling $(D nullify) can nullify it again.

Practically $(D Nullable!T) stores a $(D T) and a $(D bool). Note that being
nullified is not the same as assigning the value to a `null` value.
For example, if `T` is a class, assigning the value to `null` does not nullify
this struct.
*/
struct Nullable(T)
struct NullableWithExtraField(T)
{
// simple case: type is freely constructable
static if (__traits(compiles, { T _value; }))
Expand Down