Boost logo

Boost :

From: Karl Nelson (kenelson_at_[hidden])
Date: 2000-08-19 10:18:24


> I believe that we already have a submission which is intended to
cover this
> territory at http://www.egroups.com/files/boost/format/, by Rudiger
Loos.
> There are still a few issues with this code which haven't been
resolved. In
> particular, The constructor arguments to basic_format need to be
passed
> by-reference instead of by-value so that non-copyable classes can be
> formatted. Mr. Loos did most of his work many months ago, but at the
time
> his design met with the general agreement of all the interested
boosters. If
> any advantages to your design could be merged with the work already
done
> here, that would be ideal.

I looked over the one in current boost submission and it is really
very far from mine. I am not sure I would know even where to
begin merging them. Lets just cover the differences.

I choose to make my manipulator as close as I possibly could to
Unix 98 format specification. This does mean that many of the
charactors share identical implementations it feels more consistant
with generally accepted indicators. He does add some fancy things
like centering that mine lacks because those aren't in printf specs.
However, his format caps the number of arguments to the
format command at 9 arguments. Mine code caps out at around 256
because more than that was kind of pointless.

His is coded in charT templates. Mine is currently only 8
bit form. Although this is interesting I am
not sure how applicable it is to a UTF-8 stream. UTF-8 is exactly
that 8 bits (with variable length encoding.) I assume mine could be
changed but the details of the interactions would likely need to be
discussed.

Mine is passed on a stream proxy, so it looks like a manipulator.
His is designed to look like a function. Other manipulators do
not count as arguments in my. They do in his. His as functions
has ordering preferences, mine being a stream can not. This leads to
big differences in the sample usage.

Here is a quick comparison.

boost current:

  std::cout << format("The Truth is %2%w25%c%1",
    format("%3%4%1 != %2", 1.9999, 2.000, setprecision(5),fixed),
            setfill('.'))
            << '\n';

mine:

   std::cout << format("The Truth is %1$f != %2$f")
      << setprecision(5) << 1.9999 << 2.000 << endf;

There would be no way in mine to cap the size of the two arguments
and center them. On the other hand standardizing how to
center "1000.0000 != 10000.0000" if they came out to more than the
recommended field length seems difficult at best. Something
so fancy probably should be left to the user who would
code to drop precision over accidentally saying
"1000.0000 != 1000".

The biggest issues for my design are getting the code cleaned up and
reducing some of the memory churning that it is doing with strings.
Likely this will be done by copying the string once and then
storing list of markup indexes. But the current design is
good enough for review.

I will search for the design criterian he used in the boost list.
However, since there is such major differences I think more review of
the two designs is needed as the tradeoffs in design are quite
different.

Thanks.

--Karl Einar Nelson


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk