Essential Tools Module User's Guide : Chapter 11 Scope Guard Classes : RWScopeGuard
RWScopeGuard
RWScopeGuard encapsulates a function to invoke and a set of parameters to pass to that function. It can handle functions that take up to five parameters of any type. The function wrapped by a scope guard is invoked when the guard goes out of scope. As with other automatic objects, scope guards are destroyed in the reverse order of construction.
Construction
In general, construct an RWScopeGuard object by initializing it using one of the rwtMakeScopeGuard() functions:
 
RWScopeGuard sg0 = rwtMakeScopeGuard(free, p);
You can also copy construct it:
// ...
RWScopeGuard sg0 = rwtMakeScopeGuard(free, p);
RWScopeGuard sg2 (sg0);
RWScopeGuard sg3 = sg0;
// ...
However, because RWScopeGuard is not actually a class but a typedef for const RWScopeGuardImp&, it is not default constructible or assignable:
// ...
RWScopeGuard sg1; // fail; not default constructible
sg1 = sg0; // fail; not assignable
// ...
Member Functions
The type RWScopeGuard has only one method, to cancel the automatic invocation of the function bound to the scope guard:
 
void dismiss() const;
All other functionality relating to RWScopeGuard comes from the rwtMakeScopeGuard() and rwtMakeRef() helper functions, the latter on RWTRefHolder<T>.