The cppref page on std::format
says:
It is not an error to provide more arguments than the format string requires:
// OK, produces "Hello world!"
std::format("{} {}!", "Hello", "world", "something");
Since std::format
has a compile-time check to see if fmt
and arguments mismatch, why isn't the example code above taken as an error?
What's the rationale behind?
fmt
is static or dynamic,std::format("{} {}!", "Hello", "world", "something");
seems buggy, and the programmer should be notified. And considerstd::format("{}{}", "Hello")
is explicitly an error. – Buckeyeformat(msg, arg1, arg2)
but it's not OK to writeformat("value of msg", arg1, arg2)
. If it's not an error to not use all arguments in the dynamic case (which it's not, for good reason – this would make cases like translation where you might not need all arguments for all languages super annoying), it shouldn't be an error statically either. – Cordiacordial