Skip to content

Commit

Permalink
fix for emplace with classes
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryOlshansky committed Sep 6, 2011
1 parent 8c1a39f commit 65a0c21
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion std/conv.d
Original file line number Diff line number Diff line change
Expand Up @@ -3299,6 +3299,14 @@ T* emplace(T)(T* chunk)
memcpy(result, &i, T.sizeof);
return result;
}
///ditto
T* emplace(T)(T* chunk)
if (is(T == class))
{
*chunk = null;
return chunk;
}


/**
Given a pointer $(D chunk) to uninitialized memory (but already typed
Expand All @@ -3312,7 +3320,7 @@ Returns: A pointer to the newly constructed object (which is the same
as $(D chunk)).
*/
T* emplace(T, Args...)(T* chunk, Args args)
if (!is(T == class) && !is(T == struct) && Args.length == 1)
if (!is(T == struct) && Args.length == 1)
{
*chunk = args[0];
return chunk;
Expand Down Expand Up @@ -3493,6 +3501,26 @@ unittest
assert(foo.num == 2);
}

unittest
{
interface I {}
class K : I {}

K k = void;
emplace!K(&k);
assert(k is null);
K k2 = new K;
assert(k2 !is null);
emplace!K(&k, k2);
assert(k is k2);

I i = void;
emplace!I(&i);
assert(i is null);
emplace!I(&i, k);
assert(i is k);
}

// Undocumented for the time being
void toTextRange(T, W)(T value, W writer)
if (isIntegral!T && isOutputRange!(W, char))
Expand Down

0 comments on commit 65a0c21

Please sign in to comment.