PMT Renovated main-branch
Partition Manager Tool is a fast, reliable, and feature-rich CLI application for Android devices that enables advanced partition operations such as backup, flashing, erasing, information retrieval, and more.
Loading...
Searching...
No Matches
Helper::ScopeGuard< F > Class Template Reference

When an object created within a given scope leaves that scope, the corresponding input function is executed. More...

#include <management.hpp>

Public Member Functions

 ScopeGuard (F &&fn)
 Constructor with function input.
 
 ScopeGuard (const ScopeGuard &)=delete
 This class is not copyable.
 
 ScopeGuard (ScopeGuard &&other) noexcept
 Move constructor.
 
 ~ScopeGuard ()
 Run function if scope guard is active.
 
void now () noexcept
 Run process now.
 
void dismiss () noexcept
 Disable scope guard.
 
auto release () noexcept
 Release.
 
ScopeGuardoperator= (const ScopeGuard &)=delete
 This class is not copyable.
 

Detailed Description

template<std::invocable F>
class Helper::ScopeGuard< F >

When an object created within a given scope leaves that scope, the corresponding input function is executed.

int main(void) {
{
int fd = open("file.txt", O_RDONLY);
int* ptr = calloc(100, sizeof(int));
auto scope1 = makeScopeGuard([&] { close(fd); });
auto scope2 = makeScopeGuard([&] { free(ptr); ptr = nullptr; });
}
return 0;
}
static auto makeScopeGuard(F &&fn) noexcept
Make scope guard with input function.
Definition management.hpp:985
Template Parameters
FFunction.
See also
C++ scopes
Helper::makeScopeGuard
Note
Input functions can never be parameterized.

The documentation for this class was generated from the following file: