2008/11/11 Jeffrey Chang <jeffrey8chang@gmail.com>
Hi,

I'm using boost::format library, and this may be obvious to those experienced users:  is there any way to detect the mismatch of number of expected arguments in a
boost::format object?  Both of the following statements throw out runtime exceptions (which is correct):

std::cout << boost::format ("%s %s") % "Hello"; 
std::cout << boost::format ("%s") % "Hello" % "world"; 

It'd be great if this type of parameter-mismatch error can be caught at compile-time, instead of run-time.  We use boost::format library extensively for logging, and inevitably there're human errors like this mismatched number of arguments.  IMHO, this kind of error should have been detected by compiler at build time, s.t. the developer won't be embarrassed by QA or customers at run-time.

There is no way to do it in C++. Even gcc's __attribute__(format_arg) won't help, because boost::format does not accept ellipsis as an argument (and it also support format that is different from printf's).

Roman Perepelitsa.