www.digitalmars.com         C & C++   DMDScript  

D - Constant specialization in templates

It would be nice to be able to do something like this:

template Test(T) { int T; }
template Test(const T) { const int T; }

alias Test!(int) testDyn;
alias Test!(10) testConst;

At the moment the only work around I can think of is something like this:

struct intD { int x; } //Dynamic
struct intC { const int x = 10; } //Static

template Test(T) { int T; }

alias Test!(intD) testDyn;
alias Test!(intC) testConst;

It would be particularly useful for things like templated structs 
because you would be able to have things staticly compiled which would 
save memory and improve performace.  I could see something like this 
being used for Matthews proposed ranges.

-- 
-Anderson: http://badmama.com.au/~anderson/
Mar 23 2004