lazy variables
Steven Schveighoffer
schveiguy at gmail.com
Thu Oct 18 14:11:36 UTC 2018
On 10/18/18 10:08 AM, aliak wrote:
> On Wednesday, 17 October 2018 at 23:34:55 UTC, Paul Backus wrote:
>> On Wednesday, 17 October 2018 at 07:32:37 UTC, aliak wrote:
>>> lazy S x = () {
>>> // do some heavy stuff
>>> }();
>>>
>>> if (condition) {
>>> func(x.y); // heavy stuff evaluated here
>>> }
>>
>> auto x = () {
>> // do some heavy stuff
>> };
>>
>> if (condition) {
>> func(x().y); // heavy stuff evaluated here
>> }
>
> That would do heavy stuff everytime i wanted to get y though right?
Yes, but that's what lazy variables do.
-Steve
More information about the Digitalmars-d-learn
mailing list