Re: ref struct member function

2021-05-14 Thread Paul Backus via Digitalmars-d-learn
On Friday, 14 May 2021 at 10:00:28 UTC, PinDPlugga wrote: Hi thank you both for your answers. I had understood from an earlier chapter how this could introduce a bug, but I was confused because the warning suggests attaching ```return``` to the parameter, which is empty in the declaration.

Re: ref struct member function

2021-05-14 Thread ag0aep6g via Digitalmars-d-learn
On 14.05.21 12:00, PinDPlugga wrote: Hi thank you both for your answers. I had understood from an earlier chapter how this could introduce a bug, but I was confused because the warning suggests attaching ```return``` to the parameter, which is empty in the declaration. `this` is considered a

Re: ref struct member function

2021-05-14 Thread PinDPlugga via Digitalmars-d-learn
On Thursday, 13 May 2021 at 19:48:44 UTC, Ali Çehreli wrote: I was writing this example that shows a use case for the problem (marked with BUG below): ```D struct Fraction { auto n = 0L; auto d = 1L; // ... other bits ... ref Fraction reduce() { import std.numeric : gcd;

Re: ref struct member function

2021-05-13 Thread Ali Çehreli via Digitalmars-d-learn
On 5/13/21 12:40 PM, Steven Schveighoffer wrote: On 5/13/21 3:21 PM, PinDPlugga wrote: This works but issues a deprecation warning: ``` onlineapp.d(30): Deprecation: returning `this` escapes a reference to parameter `this` onlineapp.d(30):    perhaps annotate the parameter with `return` F

Re: ref struct member function

2021-05-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/13/21 3:21 PM, PinDPlugga wrote: This works but issues a deprecation warning: ``` onlineapp.d(30): Deprecation: returning `this` escapes a reference to parameter `this` onlineapp.d(30):    perhaps annotate the parameter with `return` Fraction(1, 3) ``` I found several other ways to m

ref struct member function

2021-05-13 Thread PinDPlugga via Digitalmars-d-learn
Hi I am working through Programming in D. In one exercise I have a helper function in a struct ```D struct Fraction { auto n = 0L; auto d = 1L; // ... other bits ... ref Fraction reduce() { import std.numeric : gcd; v = gcd(n, d); if (v > 1) { n /= v;