On Fri, Sep 18, 2020 at 06:20:41PM +0000, Andrey Zherikov via Digitalmars-d-learn wrote: > How can I rewrite foo() function as a free-function that won't cause > struct copying? My simplified code is: > ======== > struct S > { > ref S foo() return > { > return this; > } > } > > void main() > { > S().foo().foo().foo(); > } > ======== > If I write it like "auto foo(S s) { return s; }" then statement in > main() will copy value of S three times and I want to avoid this.
Why can't you return by ref, which would also avoid the copying? ref S foo(return ref S s) { return s; } T -- Let's not fight disease by killing the patient. -- Sean 'Shaleh' Perry