Binary data-structure serialization
bearophile
bearophileHUGS at lycos.com
Wed Jun 2 13:34:47 PDT 2010
Andrei Alexandrescu:
> To ensure the destructor is called, I guess we need this:
>
> @system struct StackAllocated(T)
> {
> private ubyte buffer[__traits(classInstanceSize, T)] = void;
> @property T payload() { return cast(T) buffer.ptr; }
> alias payload this;
> @disable this(); // meh
> @disable this(this);
> this(Args...)(auto ref Args args)
> {
> emplace!T(buffer.ptr, buffer.length);
> }
> ~this()
> {
> clear(payload);
> }
> }
Is this useful?
static if (__traits(hasMember, T, "__dtor")) {
~this() {
clear(payload);
}
}
Bye,
bearophile
More information about the Digitalmars-d
mailing list