Boost logo

Boost :

From: William Kempf (sirwillard_at_[hidden])
Date: 2000-11-07 14:35:02


--- In boost_at_[hidden], Thomas Maeder <maeder_at_g...> wrote:
> jbandela_at_u... wrote:
> >
> > Has anyone else seen the Generic Programming article this month on
> > CUJ Expert Forum? I personally was pretty impressed by it. I was
> > wondering if anybody else shares my opinion, and if in the future
it
> > or something like it could be incorporated into the boost library?
>
> It would be interesting to integrate the approach with the lambda
library.

Some months back I wrote a class very similar to this for use in my
COM programming. It took any valid functor type as a call back (so
LL would work great with it... only my compiler doesn't like LL). In
addition it kept a "stack" of such callbacks instead of taking only a
single callback. This made it much nicer to work with when there
were multiple operations that would need to be rolled back. If
there's interest I can clean things up and boostify them for
submission into Boost.

Example useage of my class (name changes to be more in line with
boost):

void func()
{
   scope_guard guard;

   add_record(...);
   // roll back the add if an exception occurs
   guard.push(bind(remove_record, ...));

   update_record(...);
   // roll back the changes if an exception occurs
   guard.push(bind(update_record, ...));

   // illustrates dismissing a single operation
   scope_guard::cookie c1 = guard.push(bind(update_record, ...));
   guard.dismiss(c1);

   // illustrates dismissing all registered operations
   guard.dismiss();
}

Bill Kempf


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