Why is there no lazy `format`?
burt
invalid_email_address at cab.abc
Tue Oct 20 13:28:22 UTC 2020
Hello,
I noticed that there is the function `formattedWrite`, which
outputs its resulting strings to an output range, as follows:
```
unittest
{
auto output = appender!string();
output.formattedWrite!"%s %s"(1, 2);
assert(output.data == "1 2");
}
```
But why is there no formatting function that returns a lazy input
range? That way, string formatting with (barely) any allocation
would be possible, in the following way:
```
@nogc unittest
{
auto range = formatRange!"%s %s"(42, 43);
assert(range.front == "42");
range.popFront();
assert(range.front == " ");
range.popFront();
assert(range.front == "43");
range.popFront();
assert(range.empty);
}
```
The range returned by `formatRange` could have an internal buffer
of maybe 16 characters that stores small strings, e.g. for small
integers. It would also allow chaining with other range
algorithms: you would call `.joiner()` on it to get an input
range of chars.
Is this something worth including in the standard library
(presumably in std.format)?
(The same may also be possible for `std.conv.text` but I did not
look into this.)
More information about the Digitalmars-d
mailing list