View source code Display the source code in std/conv.d from which this page was generated on github. 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 local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

std.conv.emplace - multiple declarations

Function 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. The chunk must be as least as large as T needs and should have an alignment multiple of T's alignment.

This function can be @trusted if the corresponding constructor of T is @safe.

Prototype

T* emplace(T, Args...)(
  void[] chunk,
  Args args
)
if (!is(T == class));

Returns

A pointer to the newly constructed object.

Example

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

Function emplace

Given a raw memory area chunk, constructs an object of class type T at that address. The constructor is passed the arguments Args. The chunk must be as least as large as T needs and should have an alignment multiple of T's alignment. (The size of a class instance is obtained by using _traits(classInstanceSize, T)).

This function can be @trusted if the corresponding constructor of T is @safe.

Prototype

T emplace(T, Args...)(
  void[] chunk,
  Args args
)
if (is(T == class));

Returns

A pointer to the newly constructed object.

Function emplace

Given a pointer chunk to uninitialized memory (but already typed as a non-class type T), constructs an object of type T at that address from arguments args.

This function can be @trusted if the corresponding constructor of T is @safe.

Prototypes

T* emplace(T, Args...)(
  T* chunk,
  Args args
)
if (!is(T == struct) && Args.length == 1);

T* emplace(T, Args...)(
  T* chunk,
  Args args
)
if (is(T == struct));

Returns

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

Function emplace

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

Prototype

T* emplace(T)(
  T* chunk
) pure nothrow @safe;

Returns

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

Authors

Walter Bright, Andrei Alexandrescu, Shin Fujishiro, Adam D. Ruppe, Kenji Hara

License

Boost License 1.0.

Comments