Question about @nogc in D 2.066

2014-07-11 Thread Weasel via Digitalmars-d-learn
@nogc void main(string[] args) { immutable(char)[] s1 = "hello"; immutable(int)[] a1 = [1, 2]; } Why does the s1 not throw an error, but the a1 does? As far as I can tell, they're both immutable arrays. Error is: "Error: array literal @nogc function main may cause GC allocation" It

Unique IDs for each template instantiation at compile-time?

2013-12-18 Thread Weasel
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