Extracting string parameter from template instance received via alias parameter

Ali Çehreli via Digitalmars-d digitalmars-d at puremagic.com
Fri Sep 12 13:37:43 PDT 2014


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. ;)



More information about the Digitalmars-d mailing list