Possible way to achieve lazy loading with const objects

Christophe travert at phare.normalesup.org
Wed Sep 28 04:31:31 PDT 2011


"Jonathan M Davis" , dans le message (digitalmars.D:145479), a écrit :
> But since lazy initializion will _never_ work with immutable

Never say never. One could build a clean and thread-safe way to lazily 
initialize fields. Like someone said, even without mutex, if the 
function to compute the variable is pure and based on immutable data, 
the worst case would be to run the intializing function twice. And the 
langage could include mutexes to do prevent that to happen. The fact 
that immutable data could, one day, be put in ROM doesn't mean that it 
has to. The close issue is like another-one said the issue of 
memoization of pure methods.

-- 
Christophe



More information about the Digitalmars-d mailing list