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;

Re: ref struct?

2011-10-12 Thread Steven Schveighoffer
On Sun, 09 Oct 2011 13:52:47 -0400, bearophile wrote: (I show this here because it's probably a silly idea, but it may a chance to learn something.) Do you like the idea of a POD that is always managed by reference, as class instances? ref struct Foo {} static assert(Foo.sizeof

Re: ref struct?

2011-10-11 Thread Mafi
Am 09.10.2011 19:52, schrieb bearophile: (I show this here because it's probably a silly idea, but it may a chance to learn something.) Do you like the idea of a POD that is always managed by reference, as class instances? ref struct Foo {} static assert(Foo.sizeof == 1); void

Re: ref struct?

2011-10-10 Thread Andrej Mitrovic
On 10/11/11, bearophile wrote: > Andrej Mitrovic: > >> I think this is what refcounted structs are for. > > "ref structs" are regular heap-allocated GC-managed structs, but they are > managed by reference instead of by pointer. So refcounting is not > significant here. But can't you just make a w

Re: ref struct?

2011-10-10 Thread bearophile
Andrej Mitrovic: > I think this is what refcounted structs are for. "ref structs" are regular heap-allocated GC-managed structs, but they are managed by reference instead of by pointer. So refcounting is not significant here. -- Jonathan M Davis: > That or make it a c

Re: ref struct?

2011-10-09 Thread Jonathan M Davis
On Sunday, October 09, 2011 22:42:35 Andrej Mitrovic wrote: > I think this is what refcounted structs are for. That or make it a class and make it final. - Jonathan M Davis

Re: ref struct?

2011-10-09 Thread Andrej Mitrovic
I think this is what refcounted structs are for.

ref struct?

2011-10-09 Thread bearophile
(I show this here because it's probably a silly idea, but it may a chance to learn something.) Do you like the idea of a POD that is always managed by reference, as class instances? ref struct Foo {} static assert(Foo.sizeof == 1); void main() { Foo f1; // void reference Foo f2