|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2002-09-27 11:17:06
From: "Fredrik Blomqvist" <f_blq_at_[hidden]>
> Fernando Cacciola (hotmail) wrote:
> > Consider this example of "synchronized multiple
> > updates"
> [...]
> > The goal is to achieve the basic guarantee for the
> > synchronized push_back.
> >
> > How would you do this?
> > (Without copying the whole thing just to move the
> > final state at the end, of course)
>
> David Abrahams wrote:
> [...]
> > {
> > vector1.push_back(e1);
> > try {
> > vector2.push_back(e2):
> > }
> > catch(...) {
> > vector1.pop_back();
> > throw;
> > }
>
> Isn't this a good example of something scopeguard +
> bind/lambda would be well suited to handle?
I don't really like scopeguard-like things for such jobs, since the danger
of the above is that you have to remember to throw;, while you need to
remember to cancel the scopeguard. It's an even trade. Of course if you
factor in Mr. Terekhov's favorite issue (weird entaglements with
not-really-C++ platform "exceptions"), the scopeguard might be a better
solution.
-----------------------------------------------------------
David Abrahams * Boost Consulting
dave_at_[hidden] * http://www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk