Get template name

JS js.mdnq at gmail.com
Mon Jul 29 23:45:30 PDT 2013


On Tuesday, 30 July 2013 at 06:36:12 UTC, Dicebot wrote:
> On Monday, 29 July 2013 at 23:02:57 UTC, JS wrote:
>> __FUNCTION__ does not return anything when used in templates.
>>
>> For debugging purposes I sometimes use pragma(msg, 
>> template_name); (with template_name being the name of the 
>> template assigned an enum)
>
> It can be relatively trivial or incredibly difficult, depending 
> on exact string output for a given template you want get and 
> set of template types supported.

I just want the current template name in the current scope. I 
know it seems trivial but it would help me reduce boilerplate 
code. I'm using it to debug and use the template name as a way to 
turn on debugging for specific templates if I need to analyze 
their behavior(lots of code generating templates that may have 
bugs).

A similar feature would end up being needed for functions when I 
log functions debug output.


With such a function I can just copy and paste the line to 
display the output rather than copy paste modify(replace the old 
template name with the new).

I don't need the template name of a template that called it... 
that is different, possibly useful but not required.




void f()
{
	pragma(msg, __FUNCTION__);
}

template t()
{
     pragma(msg, __FUNCTION__);
}

void main(string[] argv)
{
	readln();
}

the function displays main.f. The template displays nothing. I'd 
prefer it to display main.t! or something unique so I can use it 
as a hash.



More information about the Digitalmars-d-learn mailing list