Baffled by compilation error for formattedRead

PhilipDaniels via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 7 16:10:26 PDT 2015


Given a string

       string input = "rgb:20/30/40";

And the following:

       ubyte r, g, b;
       auto numRead = formattedRead(dropExactly(input, 4),
"%x/%x/%x", &r, &g, &b);  // does not compile
       auto numRead = formattedRead(input[4..$], "%x/%x/%x", &r, 
&g,
&b);            // does not compile

       string s2 = input[4..$];
       auto numRead = formattedRead(s2, "%x/%x/%x", &r, &g, &b);
// compiles

Why do the first two fail to compile but the last one does?! I
cannot see any difference between the 's2' case and the second
case, it is a completely mechanical source code transformation I
have made.


More information about the Digitalmars-d-learn mailing list