Re: ref for (const) variables

2015-03-18 Thread Kagamin via Digitalmars-d-learn
On Tuesday, 17 March 2015 at 18:14:48 UTC, Jonathan M Davis wrote: How long is the ref returned by getFoo even valid? Maybe it refers to memory that gets freed on the next line. The compiler can't know. The problem is not specific to variables, any reference type has that issue.

Re: ref for (const) variables

2015-03-17 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, March 16, 2015 18:46:59 Namespace via Digitalmars-d-learn wrote: May this be worth of an enhancement request? Or was this already rejected? And, no, I want no mutable references such as C++. Walter has been adamantly against having ref variables like C++ has. They're a potential

Re: ref for (const) variables

2015-03-17 Thread Namespace via Digitalmars-d-learn
On Tuesday, 17 March 2015 at 09:56:09 UTC, Jonathan M Davis wrote: On Monday, March 16, 2015 18:46:59 Namespace via Digitalmars-d-learn wrote: May this be worth of an enhancement request? Or was this already rejected? And, no, I want no mutable references such as C++. Walter has been

Re: ref for (const) variables

2015-03-17 Thread Ali Çehreli via Digitalmars-d-learn
On 03/17/2015 11:14 AM, Jonathan M Davis via Digitalmars-d-learn wrote: Or, take this example which (unfortunately) currently compiles: ref int getBar(ref int bar) @safe { return bar; } ref int getFoo() @safe { int foo; return getBar(foo); } void main() {

Re: ref for (const) variables

2015-03-17 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, March 17, 2015 09:59:59 Namespace via Digitalmars-d-learn wrote: On Tuesday, 17 March 2015 at 09:56:09 UTC, Jonathan M Davis wrote: On Monday, March 16, 2015 18:46:59 Namespace via Digitalmars-d-learn wrote: May this be worth of an enhancement request? Or was this already

Re: ref for (const) variables

2015-03-16 Thread Namespace via Digitalmars-d-learn
On Monday, 16 March 2015 at 19:20:09 UTC, anonymous wrote: On Monday, 16 March 2015 at 18:47:00 UTC, Namespace wrote: const(Matrix)* m = t.getCurrentModelViewMatrix(); // currently } But IMO it would be a lot nicer if I could store the reference like this: ref const(Matrix) m =

ref for (const) variables

2015-03-16 Thread Namespace via Digitalmars-d-learn
Currently, if you want to store a long getter into a variable without copying it (because it may be a big struct), your only way is to store it as a pointer: struct Matrix { float[16] values= [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]; }

Re: ref for (const) variables

2015-03-16 Thread anonymous via Digitalmars-d-learn
On Monday, 16 March 2015 at 18:47:00 UTC, Namespace wrote: const(Matrix)* m = t.getCurrentModelViewMatrix(); // currently } But IMO it would be a lot nicer if I could store the reference like this: ref const(Matrix) m = t.getCurrentModelViewMatrix(); // nicer [Of course

Re: ref for (const) variables

2015-03-16 Thread via Digitalmars-d-learn
On Monday, 16 March 2015 at 19:20:09 UTC, anonymous wrote: On Monday, 16 March 2015 at 18:47:00 UTC, Namespace wrote: const(Matrix)* m = t.getCurrentModelViewMatrix(); // currently } But IMO it would be a lot nicer if I could store the reference like this: ref const(Matrix) m =