The OpenD Programming Language

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, Args args)
  3. T emplace(T chunk, Args args)
  4. T emplace(void[] chunk, Args args)
  5. T* emplace(void[] chunk, 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

struct S
{
    int a, b;
}
void[S.sizeof] buf = void;
S s;
s.a = 42;
s.b = 43;
auto s1 = emplace!S(buf, s);
assert(s1.a == 42 && s1.b == 43);

Meta