is not an lvalue

Caligo iteronvexor at gmail.com
Sun Mar 11 17:55:14 PDT 2012


With the latest DMD I've noticed that the following no longer works:

struct A { int[4] _data; }

struct B {
  ref B foo(const ref A a) { }
}

B b = B().foo(A([1, 2, 3, 4]));  // Error: A() is not an lvalue


How much of a difference is 'ref' supposed to make once DMD improves
in the future?  Am I better off not using 'ref'?  I suppose I still
don't know when to go with 'ref' and when not to.

Is there supposed to be a performance difference between something like this:

// _1
struct B {
  ref B foo(const ref A a){ }
}

A a = A([1, 2, 3, 4]);
B b = B().foo(a);

and this:

// _2
struct B {
  ref B foo(A a){ }
}

B b = B().foo(A([1, 2, 3, 4]));


???

P.S.
In the past I've noticed improvement in performance when using 'ref'.
With the latest DMD, using 'ref' is actually slightly slower (at least
in the above example)


More information about the Digitalmars-d-learn mailing list