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?

Reply via email to