std.format.formattedRead docs example does not work with a string literal as input, why?

ParticlePeter via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Mar 31 11:23:21 PDT 2016


Example from docs:
string s = "hello!124:34.5";
string a;
int b;
double c;
formattedRead(s, "%s!%s:%s", &a, &b, &c);
assert(a == "hello" && b == 124 && c == 34.5);

now changing the first formattedRead argument to a string literal:
formattedRead("hello!124:34.5", "%s!%s:%s", &a, &b, &c);

results in this compiler error:
Error: template std.format.formattedRead cannot deduce function 
from argument types !()(string, string, string*, int*, double*), 
candidates are:
..\..\src\phobos\std\format.d(588,6):
std.format.formattedRead(R, Char, S...)(ref R r, const(Char)[] 
fmt, S args)

I am not getting the point that in both cases the argument is a 
string, but in the first case it is interpreted as a Range, and 
in the second case not. Why?


More information about the Digitalmars-d-learn mailing list