Problems with D const ref vs C++ const &
Craig Black
craigblack2 at cox.net
Fri Dec 10 09:48:50 PST 2010
In C++ I could to the following:
Vector3 cross(const Vector3 &a, const Vector3 &b) { ... }
and then call it like this:
Vector3 a, b, c;
a = cross(b, c);
a = cross(b-a, c-a);
But in D I have to define two functions if I want pass by reference to work:
Vector3 cross(ref const Vector3 a, ref const Vector3 b) {...}
Vector3 cross(Vector3 a, Vector3 b) {...}
Not having an l-value forces me to pass by value, and I have to define two
functions. I know about auto ref but that only works for templates, and the
compiler generates two functions which could lead to code bloat if the
function is a big one.
-Craig
More information about the Digitalmars-d
mailing list