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

#include <scoped.h>

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...
 
 ~TfScoped ()
 

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

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

The type of the function executed on destruction.

Definition at line 56 of file scoped.h.

Constructor & Destructor Documentation

template<typename T = std::function<void ()>>
TfScoped< T >::TfScoped ( const Procedure leave)
inlineexplicit

Execute leave when this object goes out of scope.

Definition at line 59 of file scoped.h.

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

Definition at line 61 of file scoped.h.


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