by CyberRabbi · 5y ago · 0 comments
I don’t understand what caused the author to assume that a compiler would elide the copy when passing a value argument to a function. That seems like an unfounded assumption to me and I don’t think there is anything sad about it not being true.
To avoid the copy in all cases the “consume” function should probably accept a reference argument. That would be idiomatic C++.
Widget && temp = complicated_long_function(...);
consume(temp);
Am i missing something?The pointer deref is unavoidable if you pass a large enough object by value, which is what’s happening here. On x86_64, generally values larger than 16 bytes are passed by reference transparently.
How does any copy-construction happen here?