Boost logo

Boost Users :

From: Aaron Griffin (aaronmgriffin_at_[hidden])
Date: 2006-10-11 15:20:33


On 10/11/06, William Xue <william.xue_at_[hidden]> 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.

variable arguments are very nasty in C++. Not only that, but the va_*
macros do not allow for type safe generic programming (or type safety
in general).

The way it works is that boost::format("..."); returns an object which
has the % operator defined. object % <anything> performs the
operation and returns the same object. This allows for chaining.

I'd assume the goal is to mirror python syntax.

The problem with something like this:
boost::format("...") % (a,b,c,d); is that C++ does not allow it. It
is not syntactically correct.


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