Boost logo

Boost :

From: Karl Nelson (kenelson_at_[hidden])
Date: 2001-12-20 12:00:29


> On Thu, 2001-12-20 at 02:52, Karl Nelson wrote:
>
> > If you want to force rules of presidence use what is given for
> > that...
> >
> > cout << (format(str) << 1 << 2) << endl;
> >
> > The class could be designed to handle that.
>
> It could, but then in those cases it would act like a string-maker, not
> a manipulator.
> (inside the parenthesis, format doesn't know about cout's state. So it
> does its formatting, and then dump a string at the end. There is no way
> to stack the arguments and wait until you get cout, before formatting
> them)

True. Though it isn't really a string maker.

I consider this
   cout << (format("A:%1 B:%2 C:%3") << 1 << 2) << 3;

to be
   cout << format("A:1 B:2 C:%3") << 3;

> So format would have a different behaviour there, and it would not be
> apparent.
> So all in all, I guess you would not make the class handle that, unless
> it always act like a string-maker like mine.

I would prefer to sweep that one under the rug as you can
place notes as to "this construct is left intentionally undefined."

> In fact, I realised you use operator<< because you aim at making format
> pretty much like a manipulator.
> while my class is a string maker , for which operator<<(stream, format)
> is define to facilitate the use inside stream output chains.
>
> that's the heart of the issue..
> In my experiments, it seemed to me it wasn't possible to make the format
> objects act like a manipulators in all aspects, I'd always get a dirty
> aspect sooner or later. I'll try to recall the details for this evening,
> to debate whether we should stick to a simple string-maker or aim for a
> 'stream manipulator' approach. This choice governs the choice between
> << and %.

On that note, it seems that I need to put up or shut up. I will
resumbit an updated copy of the manupulator type formatter.

 
> > > hum, the user forgot one of the 2 arguments (raise an exception, no ?)
> > > but I don't see the link with what I tried to say.
> >
> > 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?
>
> When an exception is raised, the developper has a chance of noticing the
> error, and correct it, instead of leaving it in the released code, where
> it will sooner or later be a nuisance on the poor user.
> But it's true that those exceptions should be possible to switch off.
> I can do that like stream's eceptions are handled.

Given that the translation strings come from outside companies it seems
like it will be a burden more often than a virtue. But if forcing the
user to place "endf" and throwing exceptions is important I can make the
code reinforce that.

> > > > cout << hex << format("%d") << 16;
> > > Who could guess that hex won't have an effect,a nd that it will print
> > > "16" instead of "10" ??
> >
> > the %d should be a clue. :-)
>
> Right :-)
> What about
> cout << hex << format("%s") << 16;
> or whatever directive you treat without modifying the stream state.
> Your format prints 10, but if you put the format inside parenthesis, it
> prints 16

Very true. But then I don't see that as a problem.

--Karl


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