std::format
takes as an argument a format string that contains replacement fields (surrounded with {}
) and a set of extra
arguments that will be formatted inside the replacement fields. Even if the format string is checked at compile-time, it is possible to have a
mismatch between the format string and the arguments. For example:
- The format string contains fewer replacement fields than the number of extra arguments:
std::format("{} {}", 1, 2, 3);
- The format string uses indexes for the replacement fields, but one index is missing:
std::format("{0} {0} {2}", 1, 2, 3);
In these cases, the extra arguments are silently ignored. In the best-case scenario, it leads to dead code. Otherwise, it is a typo, and the output
will not be intended.