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 }
Comment #2 by jack — 2016-06-03T13:49:12Z
Comment #3 by github-bugzilla — 2016-06-03T14:38:22Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/97edfbea90d72d8f4b6483c091a5b6d0e54db018 Fixed Issue 15800: std.conv.to does not work with ranges of any char type https://github.com/dlang/phobos/commit/d5119c3178826d88a1f269c58742e2a327e98d5e Merge pull request #4390 from JackStouffer/issue15800 Fixed Issue 15800: std.conv.to!int does not work with ranges of any char …
Comment #4 by github-bugzilla — 2016-10-01T11:45:03Z
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/97edfbea90d72d8f4b6483c091a5b6d0e54db018 Fixed Issue 15800: std.conv.to does not work with ranges of any char type https://github.com/dlang/phobos/commit/d5119c3178826d88a1f269c58742e2a327e98d5e Merge pull request #4390 from JackStouffer/issue15800