On Wednesday, 1 June 2016 at 19:52:01 UTC, Andrei Alexandrescu wrote:
On 06/01/2016 03:07 PM, ZombineDev wrote:
This is not autodecoding. There is nothing auto-magic w.r.t. strings in
plain foreach.

I understand where you're coming from, but it actually is autodecoding. Consider:

byte[] a;
foreach (byte x; a) {}
foreach (short x; a) {}
foreach (int x; a) {}

That works by means of a conversion short->int. However:

char[] a;
foreach (char x; a) {}
foreach (wchar x; a) {}
foreach (dchar x; a) {}

The latter two do autodecoding, not coversion as the rest of the language.


Andrei

This, deep down, point at the fact that conversion from/to char types are ill defined.

One should be able to convert from char to byte/ubyte but not the other way around. One should be able to convert from byte to short but not from char to wchar.

Once you disable the naive conversions, then the autodecoding in foreach isn't inconsistent anymore.

Reply via email to