Bug 7905 – std.conv.parse doesn't work with UFCS

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2012-04-13T23:12:00Z
Last change time
2012-04-14T21:07:08Z
Assigned to
nobody
Creator
witte2008

Comments

Comment #0 by witte2008 — 2012-04-13T23:12:27Z
import std.stdio, std.conv; void main() { // Error: template std.conv.parse does not match // any function declaration // Error: template std.conv.parse cannot deduce // function from argument types !(uint)(string) writeln("123".parse!uint()); // However, this works: string text = "123"; writeln(text.parse!uint()); // prints "123" } Also this works: auto test(T, U)(U text) { return text.parse!T(); } void main() { writeln("123".test!uint()); // prints "123" }
Comment #1 by k.hara.pg — 2012-04-13T23:25:21Z
std.conv.parse function receives the processed string with ref, and returns the remains through it. string input = "123abc"; int num = parse!int(input); assert(num == 123); assert(input == "abc"); So this is a Phobos issue, and expected behavior. "123".parse!int() never works with current Phobos. You can use std.conv.to!int("123") instead. It calls std.conv.parse and checks there is no remains.
Comment #2 by witte2008 — 2012-04-14T01:43:59Z
I see, thanks for the explanation.