Congratulations to the D Team!

Era Scarecrow rtcvb32 at yahoo.com
Wed Jul 11 11:19:51 PDT 2012


On Wednesday, 11 July 2012 at 02:02:52 UTC, Andrei Alexandrescu 
wrote:
> On 7/10/12 9:45 PM, Timon Gehr wrote:
>> I do not desire logical const as a language feature. But 
>> conservative type systems are not good for everything. The 
>> root of the class hierarchy needs to be good for everything. 
>> Object is not an adequate root any more.
>
> How about we consider just stiffening that upper lip and 
> implement comparison and hashing without modifying their target?

  I remember offering a suggested structure for cached hashing for 
const/immutable data (mostly a test/example)... If you follow a 
similar setup you could get the 'logical const' while following 
the language rules; Namely the mutable state is separate from the 
const state. Course it's sorta a wrapper, but that's better than 
breaking the type system or trying to do something else equally 
questionable.

It went something like...

struct CachedHash(T) {
  T value;
  uint hash;
  alias value this;
  uint toHash() {
   if (!hash)
    hash = value.toHash();
   return hash;
  }
}


More information about the Digitalmars-d mailing list