emplace

Given a raw memory area chunk, constructs an object of non-class type T at that address. The constructor is passed the arguments args, if any. Preconditions: chunk must be at least as large as T needs and should have an alignment multiple of T's alignment. Note: This function can be @trusted if the corresponding constructor of T is @safe.

  1. T* emplace(T* chunk)
  2. T* emplace(T* chunk, auto ref Args args)
  3. T emplace(T chunk, auto ref Args args)
  4. T emplace(void[] chunk, auto ref Args args)
  5. T* emplace(void[] chunk, auto ref Args args)
    T*
    emplace
    (
    T
    Args...
    )
    (
    void[] chunk
    ,
    auto ref Args args
    )
    if (
    !is(T == class)
    )

Return Value

Type: T*

A pointer to the newly constructed object.

Examples

1 struct S
2 {
3     int a, b;
4 }
5 auto buf = new void[S.sizeof];
6 S s;
7 s.a = 42;
8 s.b = 43;
9 auto s1 = emplace!S(buf, s);
10 assert(s1.a == 42 && s1.b == 43);
Suggestion Box / Bug Report