use template function without assignment

Meta jared771 at gmail.com
Tue Jul 30 06:16:23 PDT 2013


On Tuesday, 30 July 2013 at 07:02:51 UTC, JS wrote:
> If I use enum or alias they both have the same problem(The 
> annoying mandatory assignment).

Can you post some more code that exhibits exactly the behaviour 
you're describing? I can't replicate the problem you're having 
with the code you provided (nor the code *I* provided).

> 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?

They're semantically equivalent. The first form is just shorthand 
for the second.

> 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

What you're doing here is pretty weird. That code is equivalent 
to:

template Group(alias G1)
{
     template Group(alias G2)
     {
         void Group(int s)
         {
             writeln(s);
         }
     }
}

And I really have no idea how it *should* behave. It definitely 
doesn't work on dpaste.dzfl.pl.


More information about the Digitalmars-d-learn mailing list