formattingFunctor

Given zero or more values, returns a functor which retains a copy of these values; the functor can later be called with a sink, which will make it write the values out. The returned functor's signature varies depending on whether a format string is specified, but either way compatible with toString signatures accepted by formattedWrite If a format string is specified, that will be used to format the values; otherwise, a format string will be accepted at call time. For details, see accepted toString signatures in the "Structs, Unions, Classes, and Interfaces" section of https://dlang.org/phobos/std_format_write.html.

template formattingFunctor(string fmt = null, int line = __LINE__, T...)
formattingFunctor
(
auto ref T values
)

Members

Functions

formattingFunctor
auto formattingFunctor(T values)
Undocumented in source. Be warned that the author may not have intended to support it.

Examples

import std.array : appender;
import std.format : singleSpec;

auto a = appender!string;
auto spec = "%03d".singleSpec;
formattingFunctor(5)(a, spec);
assert(a.data == "005");
import std.array : appender;
auto a = appender!string;
formattingFunctor!"%03d"(5)(a); // or `&a.put!(const(char)[])`
assert(a.data == "005");

Meta