Re: std.algorithm move() struct emptying

2010-08-31 Thread Andrei Alexandrescu
On 8/31/10 11:28 CDT, Philippe Sigaud wrote: On Tue, Aug 31, 2010 at 17:05, Andrei Alexandrescu mailto:seewebsiteforem...@erdani.org>> wrote: On 8/31/10 7:49 CDT, Michel Fortin wrote: On 2010-08-31 06:16:17 -0400, bearophile mailto:bearophileh...@lycos.com>> said:

Re: std.algorithm move() struct emptying

2010-08-31 Thread Philippe Sigaud
On Tue, Aug 31, 2010 at 17:05, Andrei Alexandrescu < seewebsiteforem...@erdani.org> wrote: > On 8/31/10 7:49 CDT, Michel Fortin wrote: > >> On 2010-08-31 06:16:17 -0400, bearophile said: >> >> If in generic code T.init is not guaranteed to be an lvalue, as your >>> example shows, isn't it better

Re: std.algorithm move() struct emptying

2010-08-31 Thread Andrei Alexandrescu
On 8/31/10 7:49 CDT, Michel Fortin wrote: On 2010-08-31 06:16:17 -0400, bearophile said: If in generic code T.init is not guaranteed to be an lvalue, as your example shows, isn't it better to disallow (turning it into a syntax error) &T.init in all cases? Personally, I'd say the code should

Re: std.algorithm move() struct emptying

2010-08-31 Thread Stanislav Blinov
31.08.2010 16:49, Michel Fortin пишет: On 2010-08-31 06:16:17 -0400, bearophile said: If in generic code T.init is not guaranteed to be an lvalue, as your example shows, isn't it better to disallow (turning it into a syntax error) &T.init in all cases? Personally, I'd say the code should c

Re: std.algorithm move() struct emptying

2010-08-31 Thread Michel Fortin
On 2010-08-31 06:16:17 -0400, bearophile said: If in generic code T.init is not guaranteed to be an lvalue, as your example shows, isn't it better to disallow (turning it into a syntax error) &T.init in all cases? Personally, I'd say the code should check if T.init is an lvalue using __trai

Re: std.algorithm move() struct emptying

2010-08-31 Thread Stanislav Blinov
31.08.2010 0:27, Torarin wrote: Yeah, I get the enum case, but what I forgot to mention is that the example from move() is enclosed in static if (is(T == struct)) Which makes me wonder what kind of struct would have an rvalue .init. I don't know, maybe the one that's not invented yet ;)

Re: std.algorithm move() struct emptying

2010-08-31 Thread bearophile
Stanislav Blinov: > > Currently you can take its address, so doesn't that mean that it's an > > lvalue? > > No, you can't. Generally, that is. > For example: > enum A > { > a, > b > } > > void main() > { > void* p = &A.init; // won't compile > } > > You may be able to take ad

Re: std.algorithm move() struct emptying

2010-08-30 Thread Torarin
Yeah, I get the enum case, but what I forgot to mention is that the example from move() is enclosed in static if (is(T == struct)) Which makes me wonder what kind of struct would have an rvalue .init. Torarin 2010/8/30 Stanislav Blinov : > You may be able to take address of what .init returns,

Re: std.algorithm move() struct emptying

2010-08-30 Thread Stanislav Blinov
Torarin wrote: >> 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 >> Cu

Re: std.algorithm move() struct emptying

2010-08-30 Thread Torarin
Currently you can take its address, so doesn't that mean that it's an lvalue? 2010/8/30 Jonathan M Davis : > 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 : >> > On 08/29/2010 12:00 PM, Torarin wr

Re: std.algorithm move() struct emptying

2010-08-30 Thread Jonathan M Davis
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 : > > 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

Re: std.algorithm move() struct emptying

2010-08-29 Thread Torarin
Even in this case, or in some special case? Torarin 2010/8/29 Andrei Alexandrescu : > 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.size

Re: std.algorithm move() struct emptying

2010-08-29 Thread Andrei Alexandrescu
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 guarantee

Re: std.algorithm move() struct emptying

2010-08-29 Thread Torarin
Yes, you are right! Looking at the assembly, T.init creates a struct on the stack. 2010/8/29 Stanislav Blinov > > 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.s

Re: std.algorithm move() struct emptying

2010-08-29 Thread Stanislav Blinov
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

std.algorithm move() struct emptying

2010-08-29 Thread Torarin
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?