emplace

Given a pointer chunk to uninitialized memory (but already typed as T), constructs an object of non-class type T at that address. If T is a class, initializes the class reference to null.

Return Value

Type: T*

A pointer to the newly constructed object (which is the same as chunk).

Examples

1 static struct S
2 {
3     int i = 42;
4 }
5 S[2] s2 = void;
6 emplace(&s2);
7 assert(s2[0].i == 42 && s2[1].i == 42);
1 interface I {}
2 class K : I {}
3 
4 K k = void;
5 emplace(&k);
6 assert(k is null);
7 
8 I i = void;
9 emplace(&i);
10 assert(i is null);
Suggestion Box / Bug Report