std.algorithm move() struct emptying

Jonathan M Davis jmdavisprog at gmail.com
Mon Aug 30 10:34:17 PDT 2010


On Sunday, August 29, 2010 11:51:51 Torarin wrote:
> Even in this case, or in some special case?
> 
> Torarin
> 
> 2010/8/29 Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org>:
> > On 08/29/2010 12:00 PM, 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?
> > 
> > T.init is not guaranteed to be an lvalue.
> > 
> > Andrei

T.init cannot be set. It's a fixed value. When you use it, you're typically going 
to be copying it to an lvalue or creating a temporary. Temporaries aren't 
lvalues. So, T.init can be assigned to an lvalue, but it isn't itself an lvalue.

- Jonathan M Davis


More information about the Digitalmars-d mailing list