Lazily Initialized Variables that are Compatible with const/immutable

Siarhei Siamashka siarhei.siamashka at gmail.com
Thu Nov 17 12:16:41 UTC 2022


On Thursday, 17 November 2022 at 10:57:55 UTC, Vijay Nayar wrote:
> Is there another way to perform lazy initialization that is 
> compatible with const/immutable, or is this needed as a 
> language feature?

Wouldn't precomputing this const/immutable data at compile time 
via CTFE be a better idea in general?

Unless it's some sort of a sparse data structure with a huge 
memory footprint and the goal is to postpone memory allocation. 
But then you would probably also want to free memory as soon as 
possible after you are done using it and const/immutable would be 
a hindrance again.


More information about the Digitalmars-d mailing list