Passing rvalues to functions expecting const ref

Minas Mina minas_mina1990 at hotmail.co.uk
Sun Dec 23 03:41:57 PST 2012


Hi. In C++, I can do this:

struct Vector3
{
   Vector3(_x, _y, _z); // constructor
};

float dot(const Vector3 &v, const Vector3 &u);

dot(Vector3(0, 0, 0), Vector3(1, 1, 1));
------------------------------------

In D, I can't -- and it's really annoying, because I am forced to 
make a copy, i.e:
dot(Vector3 v, Vector3 u);

I don't want this.

The other solution is this:
Vector3 v = {0, 0, 0};
Vector3 u = {1, 1, 1};

dot(v,u); // dot(const ref Vector3 v, const ref Vector3 u);

But it's not as clean.
Why can't I do what I can in C++? Is it a technical or a design 
decision? Are there plans to support it?


More information about the Digitalmars-d-learn mailing list