Error: template instance does not match template declaration

ref2401 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Mar 29 11:21:33 PDT 2016


OS: Win 8.1 Pro
DMD: v2.070.0
cmd: dmd main.d -ofconsole-app.exe -debug -unittest -wi

Code is successfully compiled until I uncomment test1 function 
call in the main.
If it's uncommented I get the following compile-time error:

main.d(58): Error: template instance impl!(string, bool, 
["y":true, "n":false]) does not match template declaration 
impl(S, T, Color[string] dict)(S arg)
main.d(62): Error: template instance mainentry.test1!string error 
instantiating

What have I done wrong?
Thank you.

import std.stdio;

enum Color { RED, GREEN }

private void impl(S, T, T[string] dict)(S arg) {
	writeln("S: ", S.stringof);
	writeln("T: ", T.stringof);
	writeln("dict: ", dict);
}

unittest {
	enum COLOR_MAP = [
		"r": Color.RED,
		"g": Color.GREEN
	];

	void test0(S)(S arg) {
		impl!(S, Color, COLOR_MAP)(arg);
	}

	test0("000");
}

void test1(S)(S arg) {
	impl!(S, bool, ["y": true, "n": false])(arg);
}

void main(string[] args) {
	// test1("111"); // if you uncomment this line you'll get a 
compile-time error
}


More information about the Digitalmars-d-learn mailing list