On 11/27/2012 02:09 PM, Jack Applegame wrote:
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?
Sorry, I am not answering the question but is 'auto ref' is legal as a parameter? It is not documented.
On the other hand, 'auto ref' is a legal return type. Ali
