rvalues -> ref (yup... again!)

Walter Bright newshound2 at digitalmars.com
Mon Mar 26 22:48:38 UTC 2018


On 3/26/2018 12:24 PM, Manu wrote:
> On 26 March 2018 at 07:40, Atila Neves via Digitalmars-d
>> C++ const T& -> D T
> 
> Yeah, no... T may be big. Copying a large thing sucks. Memory copying
> is 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 for
> consideration 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).



More information about the Digitalmars-d mailing list