
Jason Stewart <jstewart@pobox.com> writes:
However, maybe using the shared_ptr semantics would work. I.e. if you can create a guard that is "uninitialized" and then reset it later to an active guard.
{ scope_guard g;
if (some condition) { g = scope_guard(my_undo_function); // do something here }
if (some other condition) { // we changed our mind, dismiss it. g = scope_guard;
// or ... // g.dismiss(); // g.reset(); // like shared_ptr
reset() is wrong unless you mean the guard to immediately take it would take upon destruction. release() would be the correct smart pointer analogy.
} }
-- Dave Abrahams Boost Consulting www.boost-consulting.com