std.algorithm move() struct emptying
Stanislav Blinov
stanislav.blinov at gmail.com
Sun Aug 29 10:14:52 PDT 2010
Torarin wrote:
> Hi,
> in std.algorithm move(), this is the operation used to set the source of
> a struct move to .init:
>
> static T empty;
> memcpy(&source, &empty, T.sizeof);
>
> Is there any particular reason why the more compact &T.init is not used?
>
I may be wrong, but it seems that in this case T.init will yield a
temporary, while static T empty is 'always' there.
Consider:
struct S {}
void main()
{
writefln("%x", &S.init); // prints one value
writefln("%x", &S.init); // prints another value
static S s;
writefln("%x", &s); // prints one value
writefln("%x", &s); // prints the same value
}
More information about the Digitalmars-d
mailing list