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.