August 02, 2013 Re: std.conv - custom string to struct conversion ? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dicebot | On Friday, 2 August 2013 at 14:02:17 UTC, Dicebot wrote:
> On Friday, 2 August 2013 at 09:59:12 UTC, monarch_dodra wrote:
>> It wouldn't because "myFile.readf("Entry: %s %s", &s, &s);" wouldn't know *what* to pass to the constructor. AFAIK. I could be wrong.
>
> It should. Pattern matching is not target-aware for readf patterns. It will simply find a whitespace separators and pass everything to the left to one constructor and everything to the right to the second one (trimming extra whitespaces).
Right, but in that case, the constructor isn't
this(string iString)
{
//Copy string here
}
but rather
this(ref string ioString)
{
//Use the string, and pop off all used elements.
}
There's a pretty big difference implementation wise.
Also, since we passed a S*, we can't call the constructor anymore (unless you emplace I guess)
|
Copyright © 1999-2021 by the D Language Foundation