compile time output
Trass3r
mrmocool at gmx.de
Tue Jan 20 12:47:33 PST 2009
BCS schrieb:
> 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]);
> }
>
Still doesn't work for this code (used with a mixin):
template classMixin()
{
static this()
{
auto members = __traits(allMembers, typeof(this));
foreach(m; Range!(0, members.length-1))
{
pragma(msg, members[m]);
static if (is (typeof(__traits(getMember, this, members[m])) F ==
function))
{
pragma(msg, "function");
}
}
}
}
-> Error: string expected for message, not 'members[0u]'
Leaving out the first pragma, compiles but doesn't output anything.
Replacing members[m] with a valid method name, such as "__ctor" it
outputs function correctly :(
More information about the Digitalmars-d-learn
mailing list