[Issue 15662] Cannot move struct with defined opAssign due to @disabled post-blit
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Fri Apr 29 05:24:56 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=15662
--- Comment #11 from Martin Nowak <code at dawg.eu> ---
Here is how you define a properly typed insertBack method.
struct Buffer(T) // T can be const/immutable
{
// value type, requires insertBack(move(val)) for non-copyable types
// compiler will perform any implicit conversions
void insertBack(T value)
{
reserve(1);
memcpy(ptr + idx, &value, T.sizeof);
// clear value, so it's destructor won't double free anything
static if (hasElaborateDestructor!T)
{
static if (!hasElaborateAssign!T && isAssignable!T)
chunk = T.init;
else
{
import core.stdc.string : memcpy;
static immutable T init = T.init;
memcpy(&value, &init, T.sizeof);
}
}
}
}
--
More information about the Digitalmars-d-bugs
mailing list