Unique IDs for each template instantiation at compile-time?
Marco Leise
Marco.Leise at gmx.de
Thu Dec 19 01:53:06 PST 2013
Am Thu, 19 Dec 2013 00:01:03 +0100
schrieb "Weasel" <weaselcat at gmail.com>:
> I was wondering if it was possible to generate unique(in order)
> IDs for each template instantiation of a class at compile-time.
>
> A short example of what I'm trying to do:
>
> static int counter = 0;
> class A(T)
> {
> enum id = counter++;
> }
> class B : A!B
> {
> }
>
> Ofcourse, this doesn't compile because the "counter" variable
> can't be read at compile-time.
Something like that cannot work. Imagine your template is in
a.d and you instantiate it in b.d and c.d. Now you compile:
dmd -c b.d
dmd -c c.d
Both times the counter imported from a.d would start at 0.
--
Marco
More information about the Digitalmars-d-learn
mailing list