On Tuesday, 30 July 2013 at 01:19:23 UTC, Meta wrote:
On Tuesday, 30 July 2013 at 01:06:39 UTC, Meta wrote:
Does this code do what you want, or are there other
requirements as well?
void Pragma(alias amsg)(string file = __FILE__)
{
pragma(msg, amsg);
}
Actually, sorry, that's the exact same code, just with some
syntactic sugar. To avoid the "expression has no effect"
problem, you could use an alias instead of an enum. You're
getting the error when you try to use pragma in the "global"
scope, right?
void Pragma(alias amsg)(string file = __FILE__)
{
pragma(msg, amsg);
}
alias temp = Pragma!("test");
In general, D doesn't have top-level expressions like what I
think you want to do here. Maybe somebody else knows a way to
work around that.
If I use enum or alias they both have the same problem(The
annoying mandatory assignment).
I see the reason why it does it but I don't know it because in
this case I do not want an effect. (pragma has no "effect" which
is what I'm trying to emulate... works well except for that
annoying quirk of having to assign it to something).
BTW, is
void Pragma(alias amsg)(string file = __FILE__)
short for
template Pragma(alias amsg)
{
void Pragma(string file = __FILE__)
or is there some real difference?
I could potential do something like
template Group(alias G1)
{
void Group(alias G2)(int s)
{
writeln(s);
}
}
Group!("x")("y")(3); // doesn't work,
Group!("x")!("y")(3); // doesn't work