E-MailRelay
Public Member Functions | List of all members
G::ScopeExit Class Reference

A class that calls an exit function at the end of its scope. More...

#include <gscope.h>

Public Member Functions

 ScopeExit (std::function< void()> fn)
 Constructor. More...
 
 ~ScopeExit ()
 Destructor. More...
 
void release () noexcept
 Deactivates the exit function. More...
 
 ScopeExit (const ScopeExit &)=delete
 
 ScopeExit (ScopeExit &&)=delete
 
ScopeExitoperator= (const ScopeExit &)=delete
 
ScopeExitoperator= (ScopeExit &&)=delete
 

Detailed Description

A class that calls an exit function at the end of its scope.

Eg:

{
int fd = open( ... ) ;
ScopeExit closer( [&](){close(fd);} ) ;
int nread = read( fd , ... ) ;
}
ScopeExit(std::function< void()> fn)
Constructor.
Definition: gscope.h:104

Definition at line 46 of file gscope.h.

Constructor & Destructor Documentation

◆ ScopeExit()

G::ScopeExit::ScopeExit ( std::function< void()>  fn)
inlineexplicit

Constructor.

Definition at line 104 of file gscope.h.

◆ ~ScopeExit()

G::ScopeExit::~ScopeExit ( )
inline

Destructor.

Calls the exit function unless release()d.

Definition at line 116 of file gscope.h.

Member Function Documentation

◆ release()

void G::ScopeExit::release ( )
inlinenoexcept

Deactivates the exit function.

Definition at line 110 of file gscope.h.


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