The variant module contains a variant, or polymorphic type.
License:
BSD style: see license.txt
Authors:
Daniel Keep, Sean Kelly
- class
VariantTypeMismatchException
: object.Exception;
- This exception is thrown whenever you attempt to get the value of a Variant
without using a compatible type.
- struct
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";
- Variant
opCall
(T)(T value);
- This pseudo-constructor is used to place a value into a new Variant.
Params:
| value |
The value you wish to put in the Variant. |
Returns:
The new Variant.
- Variant
opAssign
(T)(T value);
- This operator allows you to assign arbitrary values directly into an
existing Variant.
Params:
| value |
The value you wish to put in the Variant. |
Returns:
The new value of the assigned-to variant.
- bool
isA
(T)();
- 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.
Returns:
true if the Variant contains a value of type T, false otherwise.
- bool
isImplicitly
(T)();
- 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.
Returns:
true if the Variant contains a value of type T, or if the Variant
contains a value that can be implicitly cast to type T; false
otherwise.
- bool
isEmpty
();
- 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.
Returns:
true if the Variant does not contain a value, false otherwise.
- void
clear
();
- This member will
clear
the Variant, returning it to an empty state.
- storageT!(S)
get
(S)();
- 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.
You can check to see if this operation will fail by calling the
isImplicitly member with the type S.
Returns:
The value stored within the Variant.
- typeof(T + T)
opAdd
(T)(T rhs);
typeof(T + T)
opAdd_r
">
opAdd_r
');(T)(T lhs);
typeof(T - T)
opSub
">
opSub
');(T)(T rhs);
typeof(T - T)
opSub_r
">
opSub_r
');(T)(T lhs);
typeof(T * T)
opMul
">
opMul
');(T)(T rhs);
typeof(T * T)
opMul_r
">
opMul_r
');(T)(T lhs);
typeof(T / T)
opDiv
">
opDiv
');(T)(T rhs);
typeof(T / T)
opDiv_r
">
opDiv_r
');(T)(T lhs);
typeof(T % T)
opMod
">
opMod
');(T)(T rhs);
typeof(T % T)
opMod_r
">
opMod_r
');(T)(T lhs);
typeof(T & T)
opAnd
">
opAnd
');(T)(T rhs);
typeof(T & T)
opAnd_r
">
opAnd_r
');(T)(T lhs);
typeof(T | T)
opOr
">
opOr
');(T)(T rhs);
typeof(T | T)
opOr_r
">
opOr_r
');(T)(T lhs);
typeof(T ^ T)
opXor
">
opXor
');(T)(T rhs);
typeof(T ^ T)
opXor_r
">
opXor_r
');(T)(T lhs);
typeof(T << T)
opShl
">
opShl
');(T)(T rhs);
typeof(T << T)
opShl_r
">
opShl_r
');(T)(T lhs);
typeof(T >> T)
opShr
">
opShr
');(T)(T rhs);
typeof(T >> T)
opShr_r
">
opShr_r
');(T)(T lhs);
typeof(T >>> T)
opUShr
">
opUShr
');(T)(T rhs);
typeof(T >>> T)
opUShr_r
">
opUShr_r
');(T)(T lhs);
typeof(T ~ T)
opCat
">
opCat
');(T)(T rhs);
typeof(T ~ T)
opCat_r
">
opCat_r
');(T)(T lhs);
Variant
opAddAssign
">
opAddAssign
');(T)(T value);
Variant
opSubAssign
">
opSubAssign
');(T)(T value);
Variant
opMulAssign
">
opMulAssign
');(T)(T value);
Variant
opDivAssign
">
opDivAssign
');(T)(T value);
Variant
opModAssign
">
opModAssign
');(T)(T value);
Variant
opAndAssign
">
opAndAssign
');(T)(T value);
Variant
opOrAssign
">
opOrAssign
');(T)(T value);
Variant
opXorAssign
">
opXorAssign
');(T)(T value);
Variant
opShlAssign
">
opShlAssign
');(T)(T value);
Variant
opShrAssign
">
opShrAssign
');(T)(T value);
Variant
opUShrAssign
">
opUShrAssign
');(T)(T value);
Variant
opCatAssign
">
opCatAssign
');(T)(T value);
- 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.
- int
opEquals
(T)(T rhs);
int
opCmp
">
opCmp
');(T)(T rhs);
uint
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.
- char[]
toString
();
- Performs "stringification" of the value stored within the Variant. In
the case of the Variant having no assigned value, it will return the
string "Variant.init".
Returns:
The string representation of the value contained within the Variant.
- TypeInfo
type
();
- This can be used to retrieve the TypeInfo for the currently stored
value.
|