auto ref and arrays

Jack Applegame japplegame at gmail.com
Tue Nov 27 14:09:20 PST 2012


I don't understand why auto ref doesn't work with arrays.

void test1(T)(auto ref const T[] val) {}
void test2(T)(auto ref const T val) {}
void main() {
   int b;
   test2(b); // OK
   string a;
   test1(a); // Error: cast(const(char[]))a is not an lvalue
}

Since a is mutable itself, compiler uses ref storage class.
cast(const(char[]))a isn't an lvalue, so it's impossible to pass 
it by ref.

But cast(const int)b isn't an lvalue too. Why it's no errors in 
this case?


More information about the Digitalmars-d-learn mailing list