digitalmars.D.learn - pragma(msg,
- Ellery Newcomer (9/9) Jan 29 2011 code:
- Philippe Sigaud (4/13) Jan 30 2011 Because the inner string is not a CT constant. Put an 'enum' before.
- Ellery Newcomer (6/24) Jan 30 2011 doh.
- Philippe Sigaud (21/26) Jan 30 2011 I think in this case, your asking for an enum string, er, 'propagates'
- Ellery Newcomer (3/18) Jan 30 2011 actually, it didn't calculate it and if I passed it to a function call,
code: template tct(T1,T2){ string tct = T1.stringof ~ " " ~ T2.stringof ~ typeof(true?T1.init:T2.init).stringof; } pragma(msg, tct!(shared(const(int))*, const(int*))); result: tct why?
Jan 29 2011
On Sun, Jan 30, 2011 at 00:26, Ellery Newcomer <ellery-newcomer utulsa.edu> wrote:code: template tct(T1,T2){ =C2=A0 =C2=A0string tct =3D T1.stringof ~ " " ~ T2.stringof ~ =C2=A0 =C2=A0 =C2=A0 =C2=A0typeof(true?T1.init:T2.init).stringof; } pragma(msg, tct!(shared(const(int))*, const(int*))); result: tct why?Because the inner string is not a CT constant. Put an 'enum' before. Philippe
Jan 30 2011
On 01/30/2011 07:40 AM, Philippe Sigaud wrote:On Sun, Jan 30, 2011 at 00:26, Ellery Newcomer <ellery-newcomer utulsa.edu> wrote:doh. when I did something like enum string s = tct!(int,int); it just took it and didn't complain that it didn't know the value at compile time.code: template tct(T1,T2){ string tct = T1.stringof ~ " " ~ T2.stringof ~ typeof(true?T1.init:T2.init).stringof; } pragma(msg, tct!(shared(const(int))*, const(int*))); result: tct why?Because the inner string is not a CT constant. Put an 'enum' before. Philippe
Jan 30 2011
On Sun, Jan 30, 2011 at 19:15, Ellery Newcomer <ellery-newcomer utulsa.edu> wrote:doh. when I did something like enum string s = tct!(int,int); it just took it and didn't complain that it didn't know the value at compile time.I think in this case, your asking for an enum string, er, 'propagates' the compile-time-ness to tct!(int,int). Everything is calculated at CT, because it's doable. But when you used pragma(msg, someString), the compiler doesn't know someString can be entirely known at CT. So, there is a difference between pragma(msg, tct!(T,U)); and enum string s = tct!(T,U)); pragma(msg, s); But if you indicate to the compiler you want the result of tct to be a CT string, everything is resolved. So the easiest way is to put enum string tct = ... inside the template. I spent some time building a CT regex engine in D. Having the match/replace results shown with pragma instructions is fun, but I had horrible moments trying to understand the interplay between compile-time et runtime... Philippe
Jan 30 2011
On 01/30/2011 03:47 PM, Philippe Sigaud wrote:On Sun, Jan 30, 2011 at 19:15, Ellery Newcomer <ellery-newcomer utulsa.edu> wrote:actually, it didn't calculate it and if I passed it to a function call, then it would complain that it didn't know the valuedoh. when I did something like enum string s = tct!(int,int); it just took it and didn't complain that it didn't know the value at compile time.I think in this case, your asking for an enum string, er, 'propagates' the compile-time-ness to tct!(int,int). Everything is calculated at CT, because it's doable. But when you used pragma(msg, someString), the compiler doesn't know someString can be entirely known at CT.
Jan 30 2011