std::format
has a (compile-time and runtime) format string validation, but one thing not included in this validation is whether there are enough {}
placeholders for all arguments (excessive arguments are silently ignored).
I assume this could be useful in some rare cases (e.g if you generate the format string), but I don't need it, and I've had a few bugs because of this.
Is there anything I can do to check for this compile-time? Possibly by wrapping std::format
in my own function.
Example:
#include <format>
#include <iostream>
int main()
{
std::cout << std::format("{} {}", 1, 2, 3, 4, 5) << '\n'; // Prints `1 2`, no error!
}
NOTE: std::format
does have compile-time format string validation. They just don't check for this specific issue (excessive arguments).
You might indeed add wrappers:
Demo