D hackers requested. Dancing around postblit.
Adam D. Ruppe via Digitalmars-d
digitalmars-d at puremagic.com
Wed Nov 5 12:01:57 PST 2014
If you're willing to make it @system or @trusted, you can just
copy the data and call postblit manually:
extern(C) @safe int printf(in char*);
struct S {
~this() { printf("dtor\n"); }
this(this) { printf("postblit\n"); }
@disable S opAssign(S s);
}
S[] data;
void emplace(Struct)(ref Struct val, size_t i) {
// just blit the struct contents over
// (same thing normal assign does anyway)
(cast(ubyte*)&(data[i]))[0 .. Struct.sizeof] =
(cast(ubyte*)&val)[0 .. Struct.sizeof];
// call postblit
data[i].__postblit();
}
void main() {
data.length = 1;
S s;
emplace(s, 0);
}
Since it is a template, attribute inference should take care of
nothrow, etc.
More information about the Digitalmars-d
mailing list