Why do we have transitive const, again?
Timon Gehr
timon.gehr at gmx.ch
Sun Sep 25 06:31:24 PDT 2011
On 09/25/2011 01:18 PM, bearophile wrote:
> 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
I think it should be a language feature, as proposed by Jonathan.
More information about the Digitalmars-d
mailing list