compile-time variables?
Fraser
fraserofthenight at gmail.com
Tue May 22 16:58:00 PDT 2007
Thanks for the ideas! Unfortunately, it doesn't seem to be working (either way). Here's the complete code I tried:
--------------------
import tango.io.Stdout;
char[] ctfe_itoa(uint value)
{
if (value < 10) return "0123456789"[value .. value+1];
return ctfe_itoa(value / 10) ~ ctfe_itoa(value % 10);
}
uint Counter(){
return 1;
}
uint Counter(in uint value){
return value+1;
}
uint nextID()
{
const auto first = Counter();
const auto second = Counter(first);
const auto third = Counter(second);
return third;
}
template Foo(char[] name)
{
const char[] text = "const char[] " ~ name ~ " = \"Name: " ~ name ~ ", ID: " ~ ctfe_itoa(nextID()) ~ "\n\";";
}
mixin(Foo!("a").text);
mixin(Foo!("b").text);
mixin(Foo!("c").text);
mixin(Foo!("d").text);
mixin(Foo!("e").text);
mixin(Foo!("f").text);
int main(char[][] args)
{
Stdout(a)(b)(c)(d)(e)(f);
return 0;
}
--------------------
The result was:
Name: a, ID: 3
Name: b, ID: 3
Name: c, ID: 3
Name: d, ID: 3
Name: e, ID: 3
Name: f, ID: 3
A similar thing happened with the template example.
Pragma Wrote:
> Fraser wrote:
> > <snip>
More information about the Digitalmars-d
mailing list