You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have read about implementing custom formatters by specializing fmt::formatter (or inheriting fmt::arg_formatter), but the format function (or resp. operator()) accepts only one argument. I noticed that the basic formatter for integers allows the format string like {:{}.{}}, and consumes 3 arguments, so I wonder whether custom formatters can also do similar things.
I don't want to wrap the 3 arguments into a new structure, for I might want to reuse those arguments in the format string elsewhere, like:
Ideally, I want to support full-featured format strings in the two branches and allow omitting one branch in that ternary operator:
fmt::format("{:?{} and {:{}.{}}:}", true, "Hello", 4.2, 3, 2);
Note that in the true branch, 2 format specs and some plain text are used, while in the false branch an empty string is used (the whole branch is omitted).
The text was updated successfully, but these errors were encountered:
I want to implement a ternary-operator-like formatter:
I have read about implementing custom formatters by specializing
fmt::formatter
(or inheritingfmt::arg_formatter
), but theformat
function (or resp.operator()
) accepts only one argument. I noticed that the basic formatter for integers allows the format string like{:{}.{}}
, and consumes 3 arguments, so I wonder whether custom formatters can also do similar things.I don't want to wrap the 3 arguments into a new structure, for I might want to reuse those arguments in the format string elsewhere, like:
Ideally, I want to support full-featured format strings in the two branches and allow omitting one branch in that ternary operator:
Note that in the
true
branch, 2 format specs and some plain text are used, while in thefalse
branch an empty string is used (the whole branch is omitted).The text was updated successfully, but these errors were encountered: