Boost logo

Boost Users :

From: ShenLei (sweetmelon_at_[hidden])
Date: 2006-10-11 15:49:05


On 10/11/06, William Xue <william.xue <at> gmail.com> wrote:
> First, I am a new user of boost. I wonder of the style of
> 'boost::format( format-string ) % arg1 % arg2 % ... % argN'.
> I think it, format(...), as a function, but it seems not function in C or
> C++ style.

You are right. There is a much better implementation, Loki::Printf in
SafeFormat.h. It works like this:

Printf("1 + 1 = %d\n")(2);
-> 1 + 1 = 2
Printf("The address of %s is 0x%08lX.\n")("Var")(dwAddr);
-> The address of Var is 0x004B256A.

Each operator() returns a PrintState class object, and can be operated chainly.
Also, Loki gives us a complete printf-like functions, SPrintf, FPrintf... It
really convenient.

Compared to Loki::Printf, the boost::format is not so good. I think its
motivation is ambiguous. Actually, users want a "type-safe printf", not
a "iostream with new format rules". To use boost::format, I have to study a lot
for its gramma which makes my code un-readable to other people who do not know
boost::format. (Please forgive me the author of boost::format. ^_^)

ShenLei


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net