On Monday, 26 March 2018 at 22:48:38 UTC, Walter Bright wrote:
On 3/26/2018 12:24 PM, Manu wrote:On 26 March 2018 at 07:40, Atila Neves via Digitalmars-dC++ const T& -> D TYeah, no... T may be big. Copying a large thing sucks. Memory copyingis the slowest thing computers can do.As an API author, exactly as in C++, you will make a judgement on a case-by-case basis on this matter. It may be by-value, it may be by const-ref. It depends on a bunch of things, and they are points forconsideration by the API author, not the user.Copying does suck, I agree. Consider the following: void foo(T t) { foo(t); } <= add this overload void foo(ref T t) { ... } T aaa(); foo(aaa());With inlining, I suspect we can get the compiler to not make any extra copies. It's not that different from NRVO. And as a marvy bonus, no weird semantic problems (as Atila mentioned).
How do you add this overload for the following?
void foo(ref T t) { ... }
void function(ref int) func = &foo;
int aaa();
func(aaa()); // err
