Re: compile time output

2009-01-20 Thread Christopher Wright
Sergey Gromov wrote: Comment out the traits and it compiles. Traits are supposed to be compile-time. How's that possible for them to prevent compile-time evaluation? It's the amazing powers of the DMD CTFE engine! And it's why I don't use d2 these days. I think I'll dust off some old code

Re: compile time output

2009-01-20 Thread Bill Baxter
On Wed, Jan 21, 2009 at 8:25 AM, Trass3r wrote: > Trass3r schrieb: >> >> This works: >> >> string foo(const string[] members) >> { >>string result; >>foreach(m; members) >>result ~= m ~ " "; >>return result; >> } >> > > Furthermore there seems to be no way to use these member n

Re: compile time output

2009-01-20 Thread Trass3r
Trass3r schrieb: This works: string foo(const string[] members) { string result; foreach(m; members) result ~= m ~ " "; return result; } Furthermore there seems to be no way to use these member names in a __traits(getMember, class, m) call. This is driving me crazy.

Re: compile time output

2009-01-20 Thread Trass3r
This works: template classMixin() { static this() { const string[] members = __traits(allMembers, typeof(this)); pragma(msg, foo(members)); } } string foo(const string[] members) { string result; foreach(m; members) result ~= m ~ " "; retur

Re: compile time output

2009-01-20 Thread Sergey Gromov
Tue, 20 Jan 2009 21:12:18 + (UTC), BCS wrote: > Reply to Trass3r, > >> Sergey Gromov schrieb: >> >>> auto members = __traits(allMembers, Cls); >> >> Seeing this really simple example crashing makes me think that this >> has to be a bug. >> > > that auto might be mucking it up (if so it wou

Re: compile time output

2009-01-20 Thread BCS
Reply to Trass3r, Sergey Gromov schrieb: auto members = __traits(allMembers, Cls); Seeing this really simple example crashing makes me think that this has to be a bug. that auto might be mucking it up (if so it would be a bug).

Re: compile time output

2009-01-20 Thread BCS
Reply to Trass3r, auto members = __traits(allMembers, typeof(this)); try switching that to const[][] members = __traits(allMembers, typeof(this)); if that doesn't fix it try dropping this part (it might make it clearer what's going on) static if (is (typeof(__traits(getMember, this, m

Re: compile time output

2009-01-20 Thread Trass3r
Sergey Gromov schrieb: > class Cls { int bar; char[] baz; } string foo() { auto members = __traits(allMembers, Cls); return ""; } pragma(msg, foo()); dmd -c test.d test.d(11): Error: cannot evaluate foo() at compile time test.d(11): pragma msg string expected for message, not 'foo()'

Re: compile time output

2009-01-20 Thread Trass3r
BCS schrieb: template Tpl(T...) { alias T Tpl; } template Range(int l, int u) { static if(l 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 class

Re: compile time output

2009-01-20 Thread Sergey Gromov
Tue, 20 Jan 2009 16:36:09 +0100, Trass3r wrote: > Is there any way to output information at compile time other than > pragma(msg? > pragma is driving me crazy, the following doesn't work: > > auto members = __traits(allMembers, typeof(this)); > foreach(m; members) > { > pragma(msg, m); > }

Re: compile time output

2009-01-20 Thread BCS
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

Re: compile time output

2009-01-20 Thread 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?

Re: compile time output

2009-01-20 Thread BCS
Reply to Trass3r, Is there any way to output information at compile time other than pragma(msg? pragma is driving me crazy, the following doesn't work: auto members = __traits(allMembers, typeof(this)); foreach(m; members) { pragma(msg, m); } -> Error: string expected for message, not 'm' Thoug

Re: compile time output

2009-01-20 Thread Trass3r
Bill Baxter schrieb: try indexing explicitly or using ref: foreach(i,m; members) { pragma(msg, members[i]); } foreach(ref m; members) { pragma(msg, m); } Latter one may not be useful. I can't recall. Neither one works for me :(

Re: compile time output

2009-01-20 Thread Ary Borenszweig
Trass3r wrote: Is there any way to output information at compile time other than pragma(msg? pragma is driving me crazy, the following doesn't work: auto members = __traits(allMembers, typeof(this)); Kind of offtopic, but I tried this (with typeof(Foo) and Foo is defined in the same module)

Re: compile time output

2009-01-20 Thread Bill Baxter
On Wed, Jan 21, 2009 at 12:36 AM, Trass3r wrote: > Is there any way to output information at compile time other than > pragma(msg? > pragma is driving me crazy, the following doesn't work: > > auto members = __traits(allMembers, typeof(this)); > foreach(m; members) > { >pragma(msg, m); > }

compile time output

2009-01-20 Thread Trass3r
Is there any way to output information at compile time other than pragma(msg? pragma is driving me crazy, the following doesn't work: auto members = __traits(allMembers, typeof(this)); foreach(m; members) { pragma(msg, m); } -> Error: string expected for message, not 'm' Though the doc