Re: Returning value by ref does not create a ref. Is this intentional?

2022-01-05 Thread Tejas via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 08:58:44 UTC, Dennis wrote: On Wednesday, 5 January 2022 at 05:38:45 UTC, Tejas wrote: The entire reason I wanted to get a `ref` was so that I can avoid the `*` :( I don't know what the real code behind the reduced example is, but maybe you can structure your

Re: Returning value by ref does not create a ref. Is this intentional?

2022-01-05 Thread Dennis via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 05:38:45 UTC, Tejas wrote: The entire reason I wanted to get a `ref` was so that I can avoid the `*` :( I don't know what the real code behind the reduced example is, but maybe you can structure your code such that the subsequent modification `c = 10` happens

Re: Returning value by ref does not create a ref. Is this intentional?

2022-01-04 Thread Tejas via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 05:17:10 UTC, Stanislav Blinov wrote: It is returned. But initializing `c` with it makes a copy. Oh... Wish we had real `ref` ;( This will mutate `a`: ``` func(a) = 10; ``` Thank you for your help!

Re: Returning value by ref does not create a ref. Is this intentional?

2022-01-04 Thread Tejas via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 05:15:30 UTC, Paul Backus wrote: On Wednesday, 5 January 2022 at 04:35:12 UTC, Tejas wrote: ```d import std.stdio:writeln; ref int func(return ref int a){ a = 6; // modifies a as expected return a; } void main(){ int a = 5; auto c = func(a); // I

Re: Returning value by ref does not create a ref. Is this intentional?

2022-01-04 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 04:35:12 UTC, Tejas wrote: ```d import std.stdio:writeln; ref int func(return ref int a){ a = 6; // modifies a as expected return a; } void main(){ int a = 5; auto c = func(a); // I expected c to alias a here c = 10; // Expected to modify a as

Re: Returning value by ref does not create a ref. Is this intentional?

2022-01-04 Thread Stanislav Blinov via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 04:35:12 UTC, Tejas wrote: ```d import std.stdio:writeln; ref int func(return ref int a){ a = 6; // modifies a as expected return a; } void main(){ int a = 5; auto c = func(a); // I expected c to alias a here c = 10; // Expected to modify a as

Returning value by ref does not create a ref. Is this intentional?

2022-01-04 Thread Tejas via Digitalmars-d-learn
```d import std.stdio:writeln; ref int func(return ref int a){ a = 6; // modifies a as expected return a; } void main(){ int a = 5; auto c = func(a); // I expected c to alias a here c = 10; // Expected to modify a as well writeln(a); // prints 6 :( } ``` The