Thread overview
pragma(msg,
Jan 29, 2011
Ellery Newcomer
Jan 30, 2011
Philippe Sigaud
Jan 30, 2011
Ellery Newcomer
Jan 30, 2011
Philippe Sigaud
Jan 30, 2011
Ellery Newcomer
January 29, 2011
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?
January 30, 2011
On Sun, Jan 30, 2011 at 00:26, Ellery Newcomer <ellery-newcomer@utulsa.edu> wrote:
> 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
January 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:
>> 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

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.
January 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
January 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:
>> 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.
>

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 value