Extracting string parameter from template instance received via alias parameter

MrSmith via Digitalmars-d digitalmars-d at puremagic.com
Fri Sep 12 13:43:47 PDT 2014


On Friday, 12 September 2014 at 20:37:44 UTC, Ali Çehreli wrote:
> On 09/12/2014 12:44 PM, MrSmith wrote:
>
> > Given the following program:
> >
> > ---------------------------------
> > import std.stdio;
> >
> > template first(string s)
> > {
> >      string first(string par)
> >      {
> >          if (par == s)
> >              return "true";
> >          else
> >              return "false";
> >      }
> > }
> >
> > template second(alias firstInstance)
> > {
>
> TemplateArgsOf:
>
>         import std.traits;
>         foreach (i, arg; TemplateArgsOf!firstInstance) {
>             writefln("arg %s: %s", i, arg);
>         }
>
> Prints:
>
> arg 0: str
>
> Ali
>
> P.S. We want to see these topics over at the D.learn newsgroup. 
> ;)

Thank you, Ali. I will try to not mismatch open tabs next time =)


More information about the Digitalmars-d mailing list