Extracting string parameter from template instance received via alias parameter

MrSmith via Digitalmars-d digitalmars-d at puremagic.com
Fri Sep 12 12:44:27 PDT 2014


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)
{
	string second(string par)
	{
		// this line doesn't work
		static if (is(firstInstance : F!(str), alias F, string str))
		{
			writeln("matched ", str);
		}
		
		enum s = "XXX"; // get s from firstInstance
		// without parsing strings and using mixins
		// something like second(alias C : F!(str), alias F, string str)
		
		import std.string : icmp;
		if (icmp(par, s) == 0)
			return "true";
		else
			return "false";
	}
}

void main()
{
	writeln(first!"str"("str"));
	writeln(second!( first!"str" )("StR")); // should match string 
from first, but case insensetive
}

---------------------------------

How do I extract s parameter of first passed to second via alias 
parameter. It seems like it is not possible. Or is it?


More information about the Digitalmars-d mailing list