As title implies:

----
import std.stdio;
import std.format;

void main()
{
  string s = "42";
  int v;
  formattedRead(s, "%d", &v);
  writefln("[%s] [%s]", s, v);
}
----
[] [42]
----

Is this the "expected" behavior?

Furthermore, it is not possible to try to "save" s:
----
import std.stdio;
import std.format;
import std.range;

void main()
{
  string s = "42";
  int v;
  formattedRead(s.save, "%d", &v);
  writefln("[%s] [%s]", s, v);
}
----
main.d(9): Error: template std.format.formattedRead does not match any function template declaration C:\D\dmd.2.060\dmd2\windows\bin\..\..\src\phobos\std\format.d(526): Error: template std.format.formattedRead(R,Char,S...) cannot deduce template function from argument types !()(string,string,int*)
----

The workaround is to have a named backup:
  auto ss = s.save;
  formattedRead(ss, "%d", &v);


I've traced the root issue to formattedRead's signature, which is:
uint formattedRead(R, Char, S...)(ref R r, const(Char)[] fmt, S args);

Is there a particular reason for this pass by ref? It is inconsistent with the rest of phobos, or even C's scanf?

Is this a file-able bug_report/enhancement_request?

Reply via email to