On Saturday, 2 July 2016 at 18:47:31 UTC, phant0m wrote:
On Saturday, 2 July 2016 at 18:43:51 UTC, ketmar wrote:
void boo() (in auto ref MyStruct s) { ... }
this will accept both lvalues and rvalues, and will avoid
copying if it can.
Thank you! Could you please explain what does "auto" in this
context mean?
basically, what you think it does. ;-)
it means "use ref if you can, but fallback to copy if you can't".
so it accepts both:
MyStruct s;
boo(s);
and
boo(MyStruct());
note the first "()", though: this is effectively a template
function, which compiler will instantiate either with "ref" or
without it.