On Tuesday, January 02, 2018 19:27:50 Igor Shirkalin via Digitalmars-d-learn wrote: > On Tuesday, 2 January 2018 at 18:45:48 UTC, Jonathan M Davis > > wrote: > > [...] > > Smart optimizer should think for you without any "auto" private > words if function is inlined. I mean LDC compiler first of all.
A smart optimizer may very well optimize out a number of copies. The fact that D requires that structs be moveable opens up all kinds of optimization opportunities - even more so when stuff gets inlined. However, if you want to guarantee that unnecessary copies aren't happening, you have to ensure that ref gets used with lvalues and does not get used with rvalues, and that tends to mean either using auto ref or overloading functions on ref. - Jonathan M Davis