Boost logo

Boost :

From: vonosan (alnsn_at_[hidden])
Date: 2001-12-20 04:13:02


--- In boost_at_y..., Karl Nelson <kenelson_at_e...> wrote:
> How is the execption to be handled? What good does it do to raise
it?
> Can you provide a reasonable code where raising an exception when
> strings are being provided from an outside source will make
> a critical difference to the coder?
>

Exception handling is one more little agrument against traiting
format as manipulator. Look:
  cout << "hex: "
       << hex
       << i
       << endl;
You expected that this code will not throw exception even in stress
memory conditions. You know that operator<<'s whether set flags or
put characters directly to the stream buffer. This can be implemented
safely (and I beleive it is).
Next "equivalent" example:
  cout << start_format ( "%s%x" )
       << "hex: "
       << i
       << stop_format
       << endl;
is completely different story. Characters are accumulated in format
object and then outputed to cout. It really can throw! Users of
ostreams expected that they can safe pass to ostream most
manipulators and build-in types and they fail here.

> > That's a good point for % rather than <<.
> > In fact, in my opinion, it's the strongest point. the rest is mre
> > subjective.
> > While this one is essential : we should not use << because format
is NOT
> > a manipulator.
>
> But is a maniplator.
>

How are you going to implement this code?
  cout << start_format ( "hex: %x" );
  cout << i;
  cout << stop_format
       << endl;

I think most of us agree that we should somehow distinguish output to
stream and output to format. I prefered do not mix ostream and format
at all. Samuel Krempp prefered another operator. We all care about
clear functionality.

---------
Alexander


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