August 31, 2010 Re: std.algorithm move() struct emptying | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On 2010-08-31 06:16:17 -0400, bearophile <bearophileHUGS@lycos.com> 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 __traits(compiles, &T.init) or is(typeof(&T.init)) and avoid creating a static variable or temporary when it is. This optimization of course depends &T.init not being a syntax error. -- Michel Fortin michel.fortin@michelf.com http://michelf.com/ |
August 31, 2010 Re: std.algorithm move() struct emptying | ||||
---|---|---|---|---|
| ||||
Posted in reply to Michel Fortin | 31.08.2010 16:49, Michel Fortin пишет:
> On 2010-08-31 06:16:17 -0400, bearophile <bearophileHUGS@lycos.com> 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 __traits(compiles, &T.init) or is(typeof(&T.init)) and avoid creating a static variable or temporary when it is. This optimization of course depends &T.init not being a syntax error.
>
Well, currently there's even nastier thing than syntax error.
struct S
{
int a;
@property static S init() { return S(10); }
}
Or even
struct S
{
@property static void init() {}
}
Personally I agree with bearophile, but maybe the code such as above should be forbidden as well, and for other builtin properties too?
|
August 31, 2010 Re: std.algorithm move() struct emptying | ||||
---|---|---|---|---|
| ||||
Posted in reply to Michel Fortin | On 8/31/10 7:49 CDT, Michel Fortin wrote:
> On 2010-08-31 06:16:17 -0400, bearophile <bearophileHUGS@lycos.com> 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
> __traits(compiles, &T.init) or is(typeof(&T.init)) and avoid creating a
> static variable or temporary when it is. This optimization of course
> depends &T.init not being a syntax error.
I recall I wrote that code to avoid a compiler bug when T == Tuple!(some types).
Andrei
|
August 31, 2010 Re: std.algorithm move() struct emptying | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu Attachments:
| On Tue, Aug 31, 2010 at 17:05, Andrei Alexandrescu < SeeWebsiteForEmail@erdani.org> wrote: > On 8/31/10 7:49 CDT, Michel Fortin wrote: > >> On 2010-08-31 06:16:17 -0400, bearophile <bearophileHUGS@lycos.com> 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 >> __traits(compiles, &T.init) or is(typeof(&T.init)) and avoid creating a >> static variable or temporary when it is. This optimization of course >> depends &T.init not being a syntax error. >> > > I recall I wrote that code to avoid a compiler bug when T == Tuple!(some > types). > > Andrei > Is that related to this bug? http://d.puremagic.com/issues/show_bug.cgi?id=4536 Philippe |
August 31, 2010 Re: std.algorithm move() struct emptying | ||||
---|---|---|---|---|
| ||||
Posted in reply to Philippe Sigaud | On 8/31/10 11:28 CDT, Philippe Sigaud wrote:
> On Tue, Aug 31, 2010 at 17:05, Andrei Alexandrescu
> <SeeWebsiteForEmail@erdani.org <mailto:SeeWebsiteForEmail@erdani.org>>
> wrote:
>
> On 8/31/10 7:49 CDT, Michel Fortin wrote:
>
> On 2010-08-31 06:16:17 -0400, bearophile
> <bearophileHUGS@lycos.com <mailto:bearophileHUGS@lycos.com>> 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
> __traits(compiles, &T.init) or is(typeof(&T.init)) and avoid
> creating a
> static variable or temporary when it is. This optimization of course
> depends &T.init not being a syntax error.
>
>
> I recall I wrote that code to avoid a compiler bug when T ==
> Tuple!(some types).
>
> Andrei
>
>
> Is that related to this bug?
> http://d.puremagic.com/issues/show_bug.cgi?id=4536
>
>
> Philippe
Very possible.
Andrei
|
Copyright © 1999-2021 by the D Language Foundation