From: Samuel Krempp (krempp_at_[hidden])
Date: 2001-06-29 13:43:51
> I find the usage:
> format( format_string, arg1, arg2, ... )
> to be more flexible than what you have proposed. Most of the time that
> I use the format class, it isn't being sent to a stream. I've put an
> "operator string" and a "const char* c_str() const" functions on it to
> allow it to be passed to the logger and in constructors of exceptions.
> It still has an "operator <<" to allow it to be inserted into streams,
> if need be.
well, as of now, my format will behave exactly the same if I define this
conversion to string + c_str()
(there is already a str() function, as seen in the example program)
the "format-is-a-function" approach has big problems :
. limited number of arguments. ("well, who cares..")
. if you want good passing of arguments (ie not copy by value, but
passing T& / const T&),
you need to define 2^10 functions.. (!)
> I also like the fact that I don't have to worry about the type of the
> argument, all I've got to do is put %1, %2, etc. Granted, this is not
ah, I did not emphasize this, but the %s / %d / %x thingies dont impose
the argument to be a specific type.
it just means :
s : print as is (s like string, so no special flag of any kind)
d : print with flag 'decimal'
x : .. 'hexadecimal'
it's just a matter of flags, really, and if you dont set any, it's fine !
so "%1$s" is the equivalent to "%1" in Rüdiger Loos's boost::format.
> as flexible as far as formatting goes, but I have not once needed to do
> fancy formatting on the arguments. I always hated using printf because
> I usually had to look at the documentation to remember what to put after
> the %. I think it should be possible to support simply %1, %2, as well
I was in this case too.
but after the last 2 days, I know them by heart, including obscure
settings like padding with zeros, always printing sign..
> as all the printf stuff.
well, in fact yes ! I think we can support both at the same time, since
printf's items can never be "%1", there is no ambiguity.
that brings only avantages, so I'll do that.
as for printf compatibility, I don't have a strong opinion on that,
and I intend to leave the choice to the majority...
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk