Why don't lazy parameters bind to delegates? Was: Feature to get or add value to an associative array.

Steven Schveighoffer schveiguy at yahoo.com
Fri Apr 20 20:35:43 UTC 2018


On 4/17/18 4:49 PM, Steven Schveighoffer wrote:
> On 4/17/18 12:18 PM, Nick Treleaven wrote:
>> Thanks for making this pull, I've thought about solving this before. I 
>> think the function needs to provide a way to tell if the value was 
>> already present.
> 
> Not as straightforward, but it can be done:
> 
> bool inserted = false;
> auto p = aa.getOrAdd("key", {inserted = true; return new Person; });

Let me say I was surprised that this doesn't actually work. An in-line 
lambda will NOT work as a lazy parameter, even though that's EXACTLY 
what a lazy parameter is implemented as! And variadic lazy parameters 
are explicitly typed this way.

Has that ever worked? I could have sworn it did...

-Steve


More information about the Digitalmars-d mailing list