View mode: basic / threaded / horizontal-split · Log in · Help
March 17, 2013
Re: static property without return type
On 03/17/13 19:48, Andrej Mitrovic wrote:
> On 3/17/13, Peter Alexander <peter.alexander.au@gmail.com> wrote:
>> auto in D actually just means "I don't want to use any other storage class"
> 
>>From the user's perspective auto means more:
> 
> int x;
> ref refRet() { return x; }  // ok
> ref refRet() { return 1; }  // disallowed
> 
> auto ref autoRet() { return x; }  // ok
> auto ref autoRet() { return 1; }  // ok
> 

That's because "auto ref" is a hack.
IOW "auto ref" != "auto" + "ref", just as "static if" != "static" + "if".

artur
March 17, 2013
Re: static property without return type
On 3/17/13, Artur Skawina <art.08.09@gmail.com> wrote:
> That's because "auto ref" is a hack.
> IOW "auto ref" != "auto" + "ref", just as "static if" != "static" + "if".

Both auto and auto ref are documented features,  type inference with
any storage class is not a documented feature.
March 18, 2013
Re: static property without return type
On Sunday, 17 March 2013 at 22:11:27 UTC, Andrej Mitrovic wrote:
> On 3/17/13, Artur Skawina <art.08.09@gmail.com> wrote:
>> That's because "auto ref" is a hack.
>> IOW "auto ref" != "auto" + "ref", just as "static if" != 
>> "static" + "if".
>
> Both auto and auto ref are documented features,  type inference 
> with
> any storage class is not a documented feature.

Actually it is, and there is example with "static i = 3" but 
functions are not mentioned explicitly.

http://dlang.org/declaration.html , "Implicit Type Inference"
March 18, 2013
Re: static property without return type
On Sunday, 17 March 2013 at 22:11:27 UTC, Andrej Mitrovic wrote:
> On 3/17/13, Artur Skawina <art.08.09@gmail.com> wrote:
>> That's because "auto ref" is a hack.
>> IOW "auto ref" != "auto" + "ref", just as "static if" != 
>> "static" + "if".
>
> Both auto and auto ref are documented features,  type inference 
> with
> any storage class is not a documented feature.

Yes it is.

From the spec (http://dlang.org/declaration.html)

-- Implicit Type Inference --
If a declaration starts with a StorageClass and has a 
NonVoidInitializer from which the type can be inferred, the type 
on the declaration can be omitted.

The first example is even:
static x = 3;

Any storage class will do. No need for auto. It's not documented 
as needed, it's not implied to be needed, and it isn't needed.
March 18, 2013
Re: static property without return type
I see.
I agree with Andrej Mitrovic, it's curious feature, but 
misleading.
Next ›   Last »
1 2
Top | Discussion index | About this forum | D home