All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TfScoped< T > Class Template Reference

Execute code on exiting scope. More...

Public Types

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

Public Member Functions

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

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
* }
*

Definition at line 51 of file scoped.h.

Member Typedef Documentation

typedef T Procedure

The type of the function executed on destruction.

Definition at line 56 of file scoped.h.

Constructor & Destructor Documentation

TfScoped ( const Procedure leave)
inlineexplicit

Execute leave when this object goes out of scope.

Definition at line 59 of file scoped.h.


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