ref for (const) variables
Namespace via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Mar 16 11:46:59 PDT 2015
Currently, if you want to store a long getter into a variable
without copying it (because it may be a big struct), your only
way is to store it as a pointer:
----
struct Matrix {
float[16] values= [
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
];
}
struct Test {
private:
Matrix _matrix;
public:
ref const(Matrix) getCurrentModelViewMatrix() const pure
nothrow {
return _matrix;
}
}
void main() {
Test t;
const(Matrix)* m = &t.getCurrentModelViewMatrix(); //
currently
}
----
But IMO it would be a lot nicer if I could store the reference
like this:
----
ref const(Matrix) m = t.getCurrentModelViewMatrix(); // nicer
----
[Of course the name is exaggerated for the purpose of
demonstration.]
May this be worth of an enhancement request? Or was this already
rejected?
And, no, I want no mutable references such as C++.
More information about the Digitalmars-d-learn
mailing list