Bug 15800 – std.conv.to!int does not work with ranges of any char type
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-03-15T08:03:00Z
Last change time
2016-10-01T11:45:03Z
Assigned to
nobody
Creator
issues.dlang
Comments
Comment #0 by issues.dlang — 2016-03-15T08:03:01Z
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.
Comment #1 by jack — 2016-05-25T19:01:09Z
This issue doesn't just apply to ranges of char or wchar. Consider
import std.utf;
import std.conv;
void main()
{
auto res = "1234567".byDchar.to!int; // fails
auto res2 = "1234567".byDchar;
auto i = res2.parse!int; // works
}