On 26 March 2018 at 07:40, Atila Neves via Digitalmars-d <digitalmars-d@puremagic.com> wrote: > On Friday, 23 March 2018 at 22:01:44 UTC, Manu wrote: >> >> Forked from the x^^y thread... >> <snip> > > > There are too many replies on this thread, addressing all the comments would > take forever and pollute the thread itself. So forgive me if I say something > that was covered already by someone else. > > AFAIK being able to bind rvalues to `ref const(T)`, only makes sense when > calling C++ functions that take `const T&` (especially since that is > common). I have not yet heard any other use for them. I'd be in favour of > allowing it _only_ for `extern(C++)` functions. Otherwise use `auto ref` or > have overloads for pass-by-value and pass-by-ref. > I too, once a recent immigrant from the lands of C++, used to keep writing > `ref const(T)`. I just pass by value now. > > C++ T&& (forwarding reference) -> D auto ref T > C++ T&& (Rvalue reference) -> D T > 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. > C++ T& -> D ref T I agree the other 3 cases are correct.