Using output-range overloads of SysTime.toISO{Ext}String with formatting code
Digital Mars
drug2004 at bk.ru
Mon Jul 8 12:53:18 UTC 2019
08.07.2019 13:38, Joseph Rushton Wakeling пишет:
>
> Thanks for taking the time to answer, but I don't think this really
> addresses my question.
>
> Your example shows a struct with `toString` overloads. However,
> SysTime.toISOExtString does not work like this: it is a method with two
> explicit overloads, one of which just returns a newly allocated
> `string`, the other of which returns nothing but accepts an output range
> as input:
> https://dlang.org/phobos/std_datetime_systime.html#.SysTime.toISOExtString
>
> I want to know if there's an easy way to work with that in `format` and
> `writefln` statements.
>
> Note that while SysTime does also have `toString` methods, these give no
> control over the kind of datetime string that results:
> https://dlang.org/phobos/std_datetime_systime.html#.SysTime.toString
>
> Since I explicitly need the extended ISO format, I need to use
> `toISOExtString` directly.
Sorry that my answer wasn't thoughtful.
I guess that there is no way to have `writeln` automatically use the
output range overload instead of allocating one. You need somehow to
provide the output range to `toISOExtString` explicitly because
`writeln` outputs the return of `toISOExtString` and have no ability to
use specific overload. That is compiler calls `toISOExtString` and then
passes its return to `writeln`. Probably library solution isn't possible
in this case. Workaround is using own wrapper to provide output range to
`toISOExtString`.
More information about the Digitalmars-d-learn
mailing list