decoding foreach
Timon Gehr via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jun 2 06:14:29 PDT 2016
On 02.06.2016 12:38, deadalnix wrote:
>>
>
> 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.
The current situation is bad:
void main(){
import std.utf,std.stdio;
foreach(dchar d;"∑")
writeln(d); // "∑"
foreach(dchar d;"∑".byCodeUnit)
writeln(d); // "â", "\210", "\221"
}
Implicit conversion should not happen, and I'd prefer both of them to
behave the same. (I.e. make both a compile-time error or decode for both).
More information about the Digitalmars-d
mailing list