struct A{
int[3] _data;
ref int opIndex(size_t i) { return _data[i]; }
int opIndex(size_t i) const{ return _data[i]; }
}
T fun(T)(const ref T a){
T ai = a;
swap(ai[0], ai[1]); // error
return ai;
}
immutable A a = A();
immutable A b = fun(a);
void main(){ }
Приведенный выше код выдает следующую ошибку:
Error: ai.opIndex(0LU) is not an lvalue
Error: ai.opIndex(1LU) is not an lvalue
called from here: fun(a)
ai
является копией a
и является lvalue, поэтому я не понимаю, почему я получаю ошибку.