How will we fix opEquals?

Bruno Medeiros brunodomedeiros+spam at com.gmail
Fri Feb 25 05:32:20 PST 2011


On 23/02/2011 17:50, bearophile wrote:
> 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

(Hum, I was thinking more of the inputs to the functions, the data that 
is primarily used to determine the equality/comparison.) But that's a 
completely good and valid example nonetheless, in that it would not be 
uncommon for opHash to have some values computed lazily.
But what about the other functions, opEquals/opCmp, any examples?

-- 
Bruno Medeiros - Software Engineer


More information about the Digitalmars-d mailing list