how to write a const-object container array?

sn some at where.com
Tue Mar 11 12:57:37 PDT 2008


I want a container (array) which holds const-object, i.e. when someone get an
object out of this container, he cannot modify it using that reference.

NOTE: I don't want the container array itself to be const, I may insert or
remove object from that array.

I tried:

class A {}

int main() {
  const(A) ca[2];
  const a = new A();
  ca[0] = a;

  return 1;
}

$ dmd constarray.d
constarray.d(4): Error: slice ca[] is not mutable
constarray.d(6): Error: ca[0] isn't mutable



More information about the Digitalmars-d mailing list