Implicit string lit conversion to wstring/dstring

H. S. Teoh hsteoh at quickfur.ath.cx
Wed Mar 14 11:00:16 PDT 2012


Code:
	import std.stdio;
	version(explicit) {
		void func(dstring s) {
			dstring t = s;
			writeln(t);
		}
	} else {
		void func(S)(S s) {
			dstring t = s;	// line 10
			writeln(t);
		}
	}
	void main() {
		func("abc");
	}

If version=explicit is set, the program compiles fine. But if not, then
the compiler complains:

	test.d:10: Error: cannot implicitly convert expression (s) of type string to immutable(dchar)[]

What do I need to do to make the template version of func trigger
implicit conversion of the string lit to dstring? What I'm trying to do
is to templatize dstring as well, but still benefit from the
string->dstring conversion when instantiated with dstring.

(Ditto with implicit conversion to wstring.)


T

-- 
He who laughs last thinks slowest.


More information about the Digitalmars-d mailing list