From: Rob Stewart (stewart_at_[hidden])
Date: 2005-02-08 15:39:56
From: Daryle Walker <darylew_at_[hidden]>
> I could add a public "reset" member function to do the work of undoing the
> change, and simply have the destructor call that. This allows
> 1. Would "reset" be a good name for this member function?
"restore" or "restore_state" would be better. "reset" suggests
that it might reset the stream to defaults or avoid trying to do
anything in the dtor.
> 2. Is it worth it to complicate the current simple-RAII interface
> for 99% of users for the sake of the 'wacky' 1% that actually
> need multi-restore?
I'd hardly call that a complication. I've frequently added such
semantics to classes that were otherwise simple RAII designs and
have never seen it cause any confusion.
I can envision contexts in which I'd want to save the state,
modify it, do some custom output, restore the original state, do
some common output, and then do some more custom output, all
followed by a final state restore. Consider whether bools are
reported as numbers or strings. There may be specific output
that you want to force one style or the other, while the rest
should obey the caller's style. Yes, scoping savers will make
that work, but calling restore() is far simpler syntactically.
-- Rob Stewart stewart_at_[hidden] Software Engineer http://www.sig.com Susquehanna International Group, LLP using std::disclaimer;
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk