|
Boost : |
From: Andrey Semashev (andysem_at_[hidden])
Date: 2007-04-09 12:56:01
Hello Alexander,
Monday, April 9, 2007, 10:46:24 AM, you wrote:
> Andrey Semashev wrote:
>> Another good use case for scope guards is making rollbackable code.
>> But I see, this implementation doesn't support that.
> bool rollback = true;
> // ...
> BOOST_SCOPE_EXIT( (rollback) )
> {
> if(rollback) do_rollback();
> }
> BOOST_SCOPE_EXIT_END
> // ...
> rollback = false; // commit
Yes, that is possible. Obviously, I didn't express myself well. I
meant, it doesn't have a special support for it. What I was thinking
is somewhat like this:
guard_stack transaction;
for (int i = 0; i < n; ++i)
{
do_smth(i);
transaction.push(bind(&undo_smth, i));
}
transaction.commit();
IMHO, this looks a little more cute.
-- Best regards, Andrey mailto:andysem_at_[hidden]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk