www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Intransitive const implemented in a transitive const world

I think I got it this time.  But it's ugly and slow (lookup speed could be 
improved with an indexed array, but you'd need some sort of allocation 
routine to find an empty slot).

class X
{
  private static int[int] _mutable; // could be private global variable also
  private int instance;
  private static int uid = 0;

  this()
  {
    instance = uid++;
    mutable = 5; // change to appropriate default value
  }

  const int mutable()
  {
     return _mutable[instance];
  }

  const void mutable(int v)
  {
     _mutable[instance] = v;
  }

  ~this()
  {
     _mutable.remove(instance);
  }
}

Like I said, ugly, but it will work.

-Steve 
Sep 19 2007