|
Boost : |
From: Stewart, Robert (stewart_at_[hidden])
Date: 2002-01-24 08:39:10
From: Karl Nelson [SMTP:kenelson_at_[hidden]]
>
> > > Try deviating from the printf-like notation in the format string since
this
> > > isn't allowing for any printf-like functionality:
> > >
> > > format("[3], [1] [2]-th try")[40.23](hex)[50]["toto"];
>
> This format statement is rediculously overblown. I have enough problems
> with overloading the modulus operator to something non-directional.
> making [] take non-integer arguments seems totally out of place.
Are you familiar with std::map? It offers the subscript operator as a way
of accessing elements, and the keys need not be integers. Consequently,
there is precedence for non-integer arguments between "[" and "]".
> Can we stick to just the format with operator <<, format with operator
> %, and format with variable arguments for the discussion?
No, but we can discuss that, too.
> I still think that it is not unrealistic to simply write
>
> format(cout,"%3$s, %1$s %2$s-th try") << 40.23 << hex << 50 << "toto" ;
>
> It looks like a stream and it is compact.
I'm not the least bit familiar with Unix98 printf() format specifiers, so I
don't know what that format means. (I purposely skipped that part of the
documentation, because printf() compatibility is not important to me.) I'm
going to guess that the printf() % specifiers can have an embedded
positional indicator which is a number followed by $. Given that, and
assuming that format complains at compile time when %s isn't given a string
as shown in your example, I still have one problem: I can't tell whether
"hex" is a variable in scope at this point, or whether it std::hex brought
into scope via some IOStreams header. That may not be a likely point of
confusion for "hex," but my point is that you can't tell that 50 is argument
2, not 3.
> > By the way, Robert's approach doesn't mention about how to write
brackets.
> > Maybe we can have "%[" be a literal open square bracket, "%]" be a
literal
> > close square bracket, and "%%" be a literal percent.
>
> Why must we confuse the user with dozens of new concepts like the above?
> Printf format is well defined and widely used. Besides in an mixed
> code you would not want to send format strings with mixed formats.
> This point has been discussed many times over. If we are going to
> have a "formatted printing" it should be "formatted". If you
> want to resubmit a "reorder" manipulator for C++ streams it
> may be appropraite, but it does not negate the need for a
> formatted printing operator.
Indeed, the point I made was to split the two.
Rob
Susquehanna International Group, LLP
http://www.sig.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk