Loading...
Searching...
No Matches
TfScoped< T > Class Template Reference

Execute code on exiting scope. More...

#include <scoped.h>

Public Types

typedef T Procedure
 The type of the function executed on destruction.
 

Public Member Functions

 TfScoped (const Procedure &leave)
 Execute leave when this object goes out of scope.
 

Detailed Description

template<typename T = std::function<void ()>>
class TfScoped< T >

Execute code on exiting scope.

A TfScoped executes code when destroyed. It's useful when cleanup code should be executed when exiting the scope because it gets executed no matter how the scope is exited (e.g. normal execution, return, exceptions, etc).

int func(bool x) {
TfScoped scope(cleanup);
return func2(x); // call cleanup after calling func2
}
Execute code on exiting scope.
Definition: scoped.h:34

Definition at line 34 of file scoped.h.

Member Typedef Documentation

◆ Procedure

typedef T Procedure

The type of the function executed on destruction.

Definition at line 39 of file scoped.h.

Constructor & Destructor Documentation

◆ TfScoped()

TfScoped ( const Procedure leave)
inlineexplicit

Execute leave when this object goes out of scope.

Definition at line 42 of file scoped.h.

◆ ~TfScoped()

~TfScoped ( )
inline

Definition at line 44 of file scoped.h.


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