|
Boost : |
From: Andrey Semashev (andysem_at_[hidden])
Date: 2007-04-12 14:16:18
Hello Hans,
Thursday, April 12, 2007, 12:13:08 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.
> Although I admit such an addition to the library would be great,
> IMHO, this is outside the scope of the functionality planned here.
> Why not a Boost.Transaction library? What do you think?
Well, I have it implemented, though not documented except for doxygen
and with no tests yet (although I have plenty real-world usages of it
to be sure in its reliability to some degree).
I name it as a scope guard library and it intersects in functionality
with your proposal, which is the second reason I didn't propose it
before. But if you are interested I can upload it into vault on the
weekend (there are lots of national language comments that need to be
translated :) ).
-- 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