On Tue, 09 Jun 2015 07:04:36 -0400, Stewart Gordon <smjg_1...@yahoo.com> wrote:

Apologies if I've missed something - I haven't had much time to keep up with the discussions lately.

What is the use case for rvalue references in a garbage-collected language?

To me, it sounds like people want this feature for D purely because C++ has it.

Stewart.



If you have a function that takes a huge struct, like, as Namespace says, containing a float[16], you would want to pass by reference.

Currently, given the following code,

struct Mat4 {
    float elements[16];
}

void TakeMatrix(ref Mat4 m) { }

Then you must use it like this:

Mat4 tmp = Mat4();
TakeMatrix(tmp);

With r-value references(auto ref), you can do the following, and 'tmp' will be 'auto'matically created for you:

TakeMatrix(Mat4());

  Bit

Reply via email to