Variant

The Variant type is used to dynamically store values of different types at runtime.

You can create a Variant using either the pseudo-constructor or direct assignment.

Variant v = Variant(42);
v = "abc";

Members

Functions

clear
void clear()

This member will clear the Variant, returning it to an empty state.

opAssign
Variant opAssign(T value)

This operator allows you to assign arbitrary values directly into an existing Variant.

opBinary
auto opBinary(T rhs)

The following operator overloads are defined for the sake of convenience. It is important to understand that they do not allow you to use a Variant as both the left-hand and right-hand sides of an expression. One side of the operator must be a concrete type in order for the Variant to know what code to generate.

opBinaryRight
auto opBinaryRight(T lhs)
Undocumented in source. Be warned that the author may not have intended to support it.
opCmp
int opCmp(T rhs)

The following operators can be used with Variants on both sides. Note that these operators do not follow the standard rules of implicit conversions.

opEquals
int opEquals(T rhs)

The following operators can be used with Variants on both sides. Note that these operators do not follow the standard rules of implicit conversions.

opOpAssign
Variant opOpAssign(T value)
Undocumented in source. Be warned that the author may not have intended to support it.
toHash
hash_t toHash()

The following operators can be used with Variants on both sides. Note that these operators do not follow the standard rules of implicit conversions.

toString
string toString()

Returns a string representation of the type being stored in this Variant.

Properties

get
T get [@property getter]

This is the primary mechanism for extracting a value from a Variant. Given a destination type S, it will attempt to extract the value of the Variant into that type. If the value contained within the Variant cannot be implicitly cast to the given type S, it will throw an exception.

get
returnT!(S) get [@property getter]
Undocumented in source. Be warned that the author may not have intended to support it.
isA
bool isA [@property getter]

This member can be used to determine if the value stored in the Variant is of the specified type. Note that this comparison is exact: it does not take implicit casting rules into account.

isEmpty
bool isEmpty [@property getter]

This determines whether the Variant has an assigned value or not. It is simply short-hand for calling the isA member with a type of void.

isImplicitly
bool isImplicitly [@property getter]

This member can be used to determine if the value stored in the Variant is of the specified type. This comparison attempts to take implicit conversion rules into account.

ptr
void* ptr [@property getter]

This can be used to retrieve a pointer to the value stored in the variant.

type
TypeInfo type [@property getter]

This can be used to retrieve the TypeInfo for the currently stored value.

Static functions

fromVararg
Variant[] fromVararg(TypeInfo[] types, void* args)
Variant[] fromVararg(...)

Converts a vararg function argument list into an array of Variants.

opCall
Variant opCall(T value)

This pseudo-constructor is used to place a value into a new Variant.

opCall
Variant opCall(TypeInfo type, void* ptr)

This pseudo-constructor creates a new Variant using a specified TypeInfo and raw pointer to the value.

Meta