Why do we have transitive const, again?
bearophile
bearophileHUGS at lycos.com
Sun Sep 25 04:18:32 PDT 2011
Walter:
> struct LogicalConst(T)
> {
> @property T v() {
> if (!set) {
> _v = some_expensive_computation();
> set = true;
> }
> return _v;
> }
>
> private:
> bool set = false;
> T _v;
> }
If this idiom becomes common (thanks to its presence in D docs, etc) it is possible to add logic to the DMD front-end to recognize it (even when inlining of v() doesn't happen), and use this knowledge to perform some const-like optimizations. Is this possible and useful?
Bye,
bearophile
More information about the Digitalmars-d
mailing list