userver: utils::ScopeGuard Class Reference
Loading...
Searching...
No Matches
utils::ScopeGuard Class Referencefinal

#include <userver/utils/scope_guard.hpp>

Detailed Description

a helper class to perform actions on scope exit

Usage example:

int x = 0;
{
utils::ScopeGuard d([&x] { x = 1; });
EXPECT_EQ(x, 0);
}
EXPECT_EQ(x, 1);
Note
exception handling is done in such way that std::terminate will not be called: in the normal path of execution, exception from handler will propagate into client code, but if we leave scope because of an exception, handler's exception, if thrown, will be silenced and written into log to avoid std::terminate

Definition at line 28 of file scope_guard.hpp.

Public Types

using Callback = std::function<void()>
 

Public Member Functions

 ScopeGuard (Callback callback)
 
 ScopeGuard (const ScopeGuard &)=delete
 
 ScopeGuard (ScopeGuard &&)=delete
 
ScopeGuardoperator= (const ScopeGuard &)=delete
 
ScopeGuardoperator= (ScopeGuard &&)=delete
 
void Release () noexcept
 

Member Typedef Documentation

◆ Callback

using utils::ScopeGuard::Callback = std::function<void()>

Definition at line 30 of file scope_guard.hpp.

Constructor & Destructor Documentation

◆ ScopeGuard()

utils::ScopeGuard::ScopeGuard ( Callback callback)
inlineexplicit

Definition at line 32 of file scope_guard.hpp.

◆ ~ScopeGuard()

utils::ScopeGuard::~ScopeGuard ( )
inline

Definition at line 41 of file scope_guard.hpp.

Member Function Documentation

◆ Release()

void utils::ScopeGuard::Release ( )
inlinenoexcept

Definition at line 58 of file scope_guard.hpp.


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