"temporary" templates

Steven Schveighoffer schveiguy at gmail.com
Wed Nov 27 16:32:13 UTC 2019

On 11/27/19 11:15 AM, Steven Schveighoffer wrote:
> What I am proposing is that you can mark items as @temporary or 
> something like that, and those templates will be reevaluated each time. 
> And in the case of something like hasFoo, I'd argue it's just a thin 
> wrapper over a __traits call, so it probably should be reevaluated each 
> time.

Think of it like "weak pure". In strong pure functions, the result is 
always the same, because the data passed in is always the same. But weak 
pure functions can be used inside those functions even though their 
parameters and results can be mutable. It allows for much more pleasant 

It allows one to have the public template as "this is final, once it's 
evaluated, store it and it's always the same." But the innards, which 
can be hairy, complex, horribly performing and used only once (or maybe 
a couple times), can be left to the GC, because once the head is 
finalized, they won't be instantiated with those parameters again.

The more I think about it, the more I like the CTFE with Types as first 
class approach, because then I can use actual mutating code vs. 
immutable functional approach that is required with templates.


More information about the Digitalmars-d mailing list