Parsing a string from stdin using formattedRead

Mark smarksc at gmail.com
Wed Dec 6 21:37:45 UTC 2017


On Wednesday, 6 December 2017 at 18:57:55 UTC, Ali Çehreli wrote:
> On 12/06/2017 10:47 AM, Mark wrote:
>
> > string info = readln();
> > formattedRead(info, "%s %s", first_name, last_name);
> >
> > This piece of code works
>
> > formattedRead(readln(), "%s %s", first_name, last_name);
> >
> > But this raises a compilation error, claiming that
> formattedRead "cannot
> > deduce function from argument types".
>
> formattedRead takes the first parameter as 'ref'.
>
> I hope we can change compiler error messages like this. What it 
> means is that although the 'string' part of the argument 
> matched, it cannot be passed as 'ref' because what readln() 
> returns is an rvalue. (On the other hand, info above is an 
> lvalue.) rvalues cannot be bound to references in D.
>
> Ali


I see. That's somewhat inconvenient.

I recall there was some debate(s) about allowing rvalues as const 
references (like in C++). What was the verdict on that?


More information about the Digitalmars-d-learn mailing list