More putrid beef soup (Was: Re: Implicit string lit conversion to wstring/dstring)

H. S. Teoh hsteoh at quickfur.ath.cx
Sat Mar 17 08:57:02 PDT 2012


On Wed, Mar 14, 2012 at 02:07:04PM -0500, Andrei Alexandrescu wrote:
[...]
> Aha! This is one of those cases in which built-in magic smells of
> putrid beef soup.
[...]

It gets worse than we first thought:

	void f1(dstring x) { dstring y = x; }

	void f2()(dstring x) { dstring y = x; }
	void f2(U)(U x) if (!is(U==string)) { dstring y = x; }

	void f3(byte[] x) { byte[] y = x; }

	void f4()(byte[] x) { byte[] y = x; }
	void f4(U)(U x) if (!is(U==int[])) { byte[] y = x; }

	void main() {
		f1("abc");	// OK: "abc" deduced as dstring

		f2("abc");	// OK: "abc" defaults to string, but f2(U)(U)
				// declines U==string, so f2()(dstring) is
				// chosen, and "abc" is deduced as dstring

		f3([1,2,3]);	// OK: [1,2,3] deduced as byte[]

		f4([1,2,3]);	// Error: template test2.f4() does not match any function template declaration
				// Error: template test2.f4() cannot deduce template function from argument types !()(int[])
	}

WAT?? So "abc" will match f()(dstring x), but [1,2,3] doesn't match
f()(byte[] b)?

Upon further investigation:

	void f5(dstring s) {}
	void f6()(dstring s) {}
	void f7(byte[] s) {}
	void f8()(byte[] s) {}
	void main() {
		f5("abc");	// OK
		f6("abc");	// OK (!)
		f7([1,2,3]);	// OK

		f8([1,2,3]);	// cannot deduce template function from argument types !()(int[])
	}

WAT?


T

-- 
"You know, maybe we don't *need* enemies." "Yeah, best friends are about all I can take." -- Calvin & Hobbes


More information about the Digitalmars-d mailing list