compile time output
BCS
ao at pathlink.com
Tue Jan 20 12:10:44 PST 2009
Reply to Trass3r,
> BCS schrieb:
>
>> I don't do 2.0 but it looks to me like your mixing runtime and
>> compile time stuff. A foreach over an array is a runtime foreach.
>>
> Do you know how I could make it run at compile-time?
>
template Tpl(T...)
{
alias T Tpl;
}
template Range(int l, int u)
{
static if(l<u)
alias Tpl!(l, Range!(l+1,u)) Range;
else
alias Tpl!(l) Range;
}
const char[][] set = ["Hello"[], "world" ];
void main()
{
foreach(str; Range!(0,set.length-1)) // compile time foreach over the numbers
from 0 to set.length-1
pragma(msg, set[str]);
}
More information about the Digitalmars-d-learn
mailing list