A ScopeGuard that uses a std::function internally to allow type erasure.
This can be handy; it allows lots of ErasedScopeGuards, all with different callbacks, to be stored in a homogeneous container.
An instance of this type will automatically call its callback when it is destroyed.
ErasedScopeGuard has a few similarities with std::unique_ptr:
- Calling reset() on a unique_ptr destroys the object if it hasn't been destroyed yet and puts the unique_ptr back into a default/null state; calling reset() on an ErasedScopeGuard calls the callback if it hasn't been called yet and puts the Guard back into a default/null state.
- Calling release() on a unique_ptr returns the unique_ptr back to a default state without destroying the managed object; calling release() on an ErasedScopeGuard returns the Guard back to a default state without calling the callback.
- Moving a unique_ptr transfers the responsibility of destroying the managed object to another unique_ptr instance; moving an ErasedScopeGuard transfers the responsibility of calling the callback to another Guard instance.
@tags{Core}