std.algorithm move() struct emptying

Torarin torarind at gmail.com
Mon Aug 30 11:16:53 PDT 2010


Currently you can take its address, so doesn't that mean that it's an lvalue?

2010/8/30 Jonathan M Davis <jmdavisprog at gmail.com>:
> 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