use template function without assignment

Meta jared771 at gmail.com
Mon Jul 29 18:06:38 PDT 2013


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.

Does this code do what you want, or are there other requirements 
as well?

void Pragma(alias amsg)(string file = __FILE__)
{
	pragma(msg, amsg);
}


More information about the Digitalmars-d-learn mailing list