LibQuicR
quicr::ScopeGuard< F > Class Template Reference

Non-copyable RAII guard that invokes a callable at scope exit. More...

#include <defer.h>

Public Member Functions

 ScopeGuard (F &&f)
 Takes ownership of a callable to run at destruction. More...
 
 ScopeGuard (const ScopeGuard &other)=delete
 Scope guards cannot be copied. More...
 
ScopeGuard & operator= (const ScopeGuard &other)=delete
 Scope guards cannot be copy-assigned. More...
 
 ~ScopeGuard () noexcept
 Invokes the stored callable. More...
 

Detailed Description

template<typename F>
class quicr::ScopeGuard< F >

Non-copyable RAII guard that invokes a callable at scope exit.

Template Parameters
FCallable type, stored by value.
Note
The guard is not thread-safe; synchronize concurrent access to captured state externally.

Constructor & Destructor Documentation

◆ ScopeGuard() [1/2]

template<typename F >
quicr::ScopeGuard< F >::ScopeGuard ( F &&  f)
inlineexplicit

Takes ownership of a callable to run at destruction.

Parameters
fCallable moved into the guard.
Exceptions
Anyexception thrown while moving f.

◆ ScopeGuard() [2/2]

template<typename F >
quicr::ScopeGuard< F >::ScopeGuard ( const ScopeGuard< F > &  other)
delete

Scope guards cannot be copied.

Parameters
otherGuard that cannot be copied.

◆ ~ScopeGuard()

template<typename F >
quicr::ScopeGuard< F >::~ScopeGuard ( )
inlinenoexcept

Invokes the stored callable.

Warning
If the callable throws, std::terminate is called.

Member Function Documentation

◆ operator=()

template<typename F >
ScopeGuard& quicr::ScopeGuard< F >::operator= ( const ScopeGuard< F > &  other)
delete

Scope guards cannot be copy-assigned.

Parameters
otherGuard that cannot be copied.
Returns
*this.

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