Boost logo

Boost Users :

From: me22 (me22.ca_at_[hidden])
Date: 2005-12-16 02:12:26


On 15/12/05, Buster <booster_at_[hidden]> wrote:
> map1[5] = "hello"; // does NOT commit to container or database
> list1.push_back(1.0); // does NOT commit either
> t.commit(); // Finally commits to container and database.
> // Without this call, t would call rollback
> // in destructor.
>

http://www.cuj.com/documents/s=8000/cujcexp1812alexandr/alexandr.htm

The scopeguard trick will work in any case where you have a rollback
function that is nofail -- such as erase in a map or pop_back in a
list. For more complex tasks you'll need a more complex solution, but
ScopeGuard is quite simple and elegant for many.

I wrote an implementation you're free to use or imitate or whatever:
http://www.uploadthis.co.uk/uploads/me22/guard.hpp

- Scott McMurray


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net