www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15800] New: std.conv.to!int does not work with ranges of char


          Issue ID: 15800
           Summary: std.conv.to!int does not work with ranges of char or
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: issues.dlang jmdavisProg.com

The following code fails to compile

import std.conv;
import std.utf;

void main()
    auto i = to!int(byCodeUnit("10"));
    auto j = to!int(byCodeUnit("10"w));
    auto l = to!int(byCodeUnit("10"d));

Specifically, for byCodeUnit on a string or wstring, which results in a range
of char and wchar respectively, std.conv.to fails to compile. It works in the
third case, because byCodeUnit on a dstring just gives you the dstring, but the
other two fail to compile. And given the move towards using stuff like
byCodeUnit instead of relying on autodecoding in string processing in Phobos,
std.conv.to really should work with ranges of char and wchar just like it does
with ranges of dchar. Presumably, this an issue for any conversions from a
range of char or wchar, but I don't know if we want separate issues for
different types or just one for them all. Regardless, the case that I ran into
was to!int, and that definitely doesn't work right now.

Mar 15 2016