On Tuesday, 30 July 2013 at 07:12:11 UTC, Namespace wrote:
On Monday, 29 July 2013 at 23:09:20 UTC, JS wrote:
I have created a template Pragma that emulates pragma but
better, the problem is that I have to assign it to something
which is very redundant in my code:
enum temp = Pragma!(msg)
e.g.,
template Pragma(alias amsg)
{
string Pragma(string file = __FILE__)
{
pragma(msg, amsg);
return "";
}
}
When I try to use void instead of string and do something like
Pragma!(msg)
I get an error that the template has no effect. It does have
an effect but what it is complaining about is exactly what I
want.
I've tried all kinds of combinations(mixins work but I then
can't ise __FILE__) and nothing works. Maybe someone has an
idea.
You could call your template in a static CTor:
----
import std.stdio;
template Pragma(alias amsg)
{
void Pragma(string file = __FILE__)
{
pragma(msg, amsg);
}
}
static this() {
Pragma!("foo")();
}
void main()
{
writeln("Hello world!");
}
----
Maybe this helps?
This is useless. It's goal is to debug templates and essentially
just wrapping pragma to supply the __FILE__ info automatically.
e.g., instead of having to do
pragma(msg, __FILE__~amsg);
I want to do Pragma!(amsg);
where Pragma custom formats the error or info message with the
location where the message was initiated.
Sticking it in a ctor will only print a message from that
location.