an output range, where the formatted result is written to
a variadic list of arguments to be formatted
the type of the writer w
character type of fmt
a variadic list of types of the arguments
The index of the last argument that was formatted. If no positional arguments are used, this is the number of arguments that where formatted.
A FormatException if formatting did not succeed.
Note: In theory this function should be @nogc. But with the current implementation there are some cases where allocations occur. See $(D sformat) for more details.
import std.array : appender; auto writer1 = appender!string(); formattedWrite(writer1, "%s is the ultimate %s.", 42, "answer"); assert(writer1[] == "42 is the ultimate answer."); auto writer2 = appender!string(); formattedWrite(writer2, "Increase: %7.2f %%", 17.4285); assert(writer2[] == "Increase: 17.43 %");
The format string can be checked at compile-time:
import std.array : appender; auto writer = appender!string(); writer.formattedWrite!"%d is the ultimate %s."(42, "answer"); assert(writer[] == "42 is the ultimate answer."); // This line doesn't compile, because 3.14 cannot be formatted with %d: // writer.formattedWrite!"%d is the ultimate %s."(3.14, "answer");
Converts its arguments according to a format string and writes the result to an output range.
The second version of formattedWrite takes the format string as a template argument. In this case, it is checked for consistency at compile-time.