How can I set a different gsl::final_action
inside an if
statement, since assignment constructor on final_action
is deleted? In the example below, I only want to create
and delete
a resource if condition
, but delete_resource
should be called at the end of the parent scope, not the if
block.
some* resource = nullptr;
auto cleanup = gsl::finally([] {});
if (condition) {
resource = create_resource();
cleanup = gsl::finally([&] { delete_resource(resource); }); // ERROR
}