Intransitive const implemented in a transitive const world

Steven Schveighoffer schveiguy at yahoo.com
Wed Sep 19 11:23:15 PDT 2007


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 





More information about the Digitalmars-d mailing list