How will we fix opEquals?

bearophile bearophileHUGS at lycos.com
Wed Feb 23 09:50:14 PST 2011


Bruno Medeiros:

> The good news is that I suspect the fields used for 
> opEquals/opCmp/opHash in any class are unlikely to be fields that are 
> computed lazily. It's just a guess though, anyone have examples otherwise?

If I have a string type, I'd like to compute its hash value lazily, the first time I need it. Computing it requires time, it's useful for sets and associative arrays, but being the string immutable the result doesn't change, so you want to compute it only once. So only the array of chars is immutable, while the hash is computed lazily and is not immutable (it 's "lazily immutable").

Bye,
bearophile


More information about the Digitalmars-d mailing list