D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7905 - std.conv.parse doesn't work with UFCS
Summary: std.conv.parse doesn't work with UFCS
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-13 23:12 UTC by Philip Witte
Modified: 2012-04-14 21:07 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Philip Witte 2012-04-13 23:12:27 UTC
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 Kenji Hara 2012-04-13 23:25:21 UTC
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 Philip Witte 2012-04-14 01:43:59 UTC
I see, thanks for the explanation.