How to convert member function to free function?

Andrey Zherikov andrey.zherikov at gmail.com
Fri Sep 18 18:20:41 UTC 2020


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.



More information about the Digitalmars-d-learn mailing list