compile-time variables?
BCS
ao at pathlink.com
Tue May 22 12:28:05 PDT 2007
Reply to Robert,
> Hi,
>
> D has some pretty impressive metaprogramming features, but I was
> wondering if there was any way to do compile-time variables, or fake
> it with recursive templates or something. In particular, I want a
> mixin template that mixes in a unique numeric ID as part of a
> function every time it's used in a mixin. Thouands of these functions
> will be used in the program, and each must have a unique ID in an
> associative array (after they're called for the first time, lazy eval
> is being done at runtime).
>
> If I can avoid code bloat, all the Better!
>
> Thanks,
> Fraser
it's does stuff at runtime but this should work
int val = 0
class UID(char[] file, int line, A...)
{
static const uid;
static this(){uid = val++}
}
UID!(__FILE__, __LINE__).uid
if it is used in a template, add enough of the template args to make each
instance have different args.
More information about the Digitalmars-d
mailing list