Report a bug
If you spot a problem with this page, click here to create a GitHub issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.


Conversion utilities.
Phobos Team, Ilya Yaroshenko
template to(T)
The to template converts a value from one type to another. The source type is deduced and the target type must be specified, for example the expression to!int(42.0) converts the number 42 from double to int. The conversion is "unsafe", i.e., it does not check for overflow.
ref T to(A...)(auto ref A args)
if (A.length > 0);
pure nothrow @trusted void emplaceInitializer(T)(ref scope T chunk);
Emplace helper function.
nothrow @nogc T[] uninitializedFillDefault(T)(return scope T[] array);
static struct S { int x = 42; @disable this(this); }

int[5] expected = [42, 42, 42, 42, 42];
S[5] arr = void;
assert((cast(int*) arr.ptr)[0 .. arr.length] == expected);
int[] a = [1, 2, 4];
assert(a == [0, 0, 0]);
void xdestroy(T)(scope T[] ar);
Destroy structs and unions usnig __xdtor member if any. Do nothing for other types.
__gshared int d;
__gshared int c;
struct D { ~this() nothrow @nogc {d++;} }
struct C { ~this() nothrow @nogc {c++;} }
C[2] carray;
D[2] darray;
assert(c == 2);
assert(d == 2);
c = 0;
d = 0;