strange resuts with .stringof and template

BCS ao at pathlink.com
Fri Jul 20 10:03:31 PDT 2007


|import std.stdio;
|
|template T(A...){alias A T;}
|struct Baz
|{
|	template Bar(char[] str)
|	{
|		pragma(msg,"B:"~str);
|		bool Bar;
|	}
|}
|
|void main()
|{
|	Baz v;
|	foreach(i,j;T!(1,2,3,4))
|	{
|		static const char[] s = i.stringof;
|		pragma(msg,"1:"~s);
|		v.Bar!(s) = !!(j&0x01);
|		writef("%d, %s : %s\n", i, v.Bar!(i.stringof), !!(j&0x01));
|	}
|	writef("\n");
|	foreach(i,j;T!(1,2,3,4))
|	{
|		static const char[] s = i.stringof;
|		pragma(msg,"2:"~s);
|		writef("%d, %s : %s\n", i, v.Bar!(s), !!(j&0x01));
|	}
|}


compiles outputting:
1:0
B:0
B:uint
1:1
1:2
1:3
2:0
2:1
2:2
2:3

should be
1:0
B:0
1:1
B:1
1:2
B:2
1:3
B:3
2:0
2:1
2:2
2:3

runs giving:
0, true : true
1, false : false
2, true : true
3, false : false

0, false : true
1, false : false
2, false : true
3, false : false




More information about the Digitalmars-d-learn mailing list