Converting an integer to a string with std.format.

Vijay Nayar madric at gmail.com
Mon Jan 7 11:48:43 UTC 2019


On Sunday, 6 January 2019 at 21:53:31 UTC, Per Nordlöw wrote:
> When converting a single integer to a string is `formatValue` 
> preferred over `formattedWrite` in terms of compilation and 
> run-time performance?

Also, if you do not need to write to a stream or a range and just 
need the value, `format("%s", value)` works as well as std.conv's 
`to!string(value)`.

But between the two functions, it seems that the only difference 
is that `formattedWrite` only accepts the exact values that go on 
the output range (such as an integer), and `formatValue` has 
extra logic to convert structs, classes, and unions into strings 
by calling their `toString()` method.


More information about the Digitalmars-d-learn mailing list