On 2016-01-13 22:20, H. S. Teoh via Digitalmars-d-learn wrote:

Isn't that just a matter of replacing each of the segments with their
range equivalents? Also, std.format.formattedWrite will do
writeln-formatting into a buffer (well, any output range, really) -- I'm
pretty sure it doesn't allocate, at least for the simplest cases like
converting an integer. So you should be able to do something like this:

        auto data = [ 1, 2, 3, 4, 5 ];
        char[] buf = ...;
        formattedWrite(buf, "[%(%d, %)]", data);

Aha, interesting. I didn't know formattedWrite could format an array/range directly like that.

The more complex example works by defining "toString" which takes an output range (delegate). But what if I need to format a third party type that I cannot add methods to? UFCS does not seem to work.

--
/Jacob Carlborg

Reply via email to