Incrementing a variable in CTFE?

bearophile bearophileHUGS at lycos.com
Fri Nov 9 10:03:12 PST 2012


Maxime Chevalier:

> I'd like to be able to increment a variable each time I 
> evaluate my code generation function in the mixin statement. 
> This is so I can generate a unique id number for each data 
> structure. Is there any way to do this? Could I increment a 
> CTFE global somehow, or use something like C's static local 
> variables?

CTFE allows you to use only locally pure code. So you can't 
modify globals or other static mutables.

I have several times suggested to add to D something similar to 
the Gensym you see in CommonLisp.

But maybe you are able to keep a local counter inside the 
function that calls the functions that generate the strings.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list