In javascript, with "const" keyword, you assign an object to a variable. Later, you cannot assign anything else to that variable, but content of it still can be changed. No matter by using "immutable" or "const", I cannot imitate that. Is there a way to do this without an overhead (like calling a function to create a pointer)?
Example:
class Test
{
public int[] a;
public this(){ a = new int[5]; }
@property auto b(){ return a.ptr; } // this is a possibility, but results with overhead of calling. Also, b is not an array anymore, just int*.
}
I want this to be possible:
test.a[3] = 7;
But this wouldn't be allowed:
test.a = new int[14];