Idea for avoiding GC for lambdas

Steven Schveighoffer schveiguy at gmail.com
Wed Jun 23 13:43:21 UTC 2021


On 6/23/21 7:04 AM, Ola Fosheim Grøstad wrote:
> On Tuesday, 22 June 2021 at 14:49:34 UTC, Steven Schveighoffer wrote:
>> I was kinda hoping for the compiler to assist in the generation and 
>> management of the context data since it's already doing it. The 
>> receiving function just needs a variable to receive and pass the 
>> context data to the lambda.
> 
> Off the top of my head:
> 
> I think it should just be an ordinary template parameter. Then you can 
> let the compiler do the optimization if is possible without changing the 
> semantics.
> 
> That way it isn't a language change.

Well, the library function needs to signify to the compiler that the 
parameter is meant to accept the value context. Otherwise, really odd 
things might happen with existing template parameters.

> So you could instead just introduce a UDA that signals that a compiler 
> should issue a warning if it cannot do the optimization?
> 
> Or am I wrong?
> 

A UDA might work.

-Steve


More information about the Digitalmars-d mailing list