AGX Dynamics 2.41.1.2
Loading...
Searching...
No Matches
agxUtil::OnScopeExit< Callback > Class Template Reference

Register a callback to be called at the end of the current scope. More...

#include <OnScopeExit.h>

Public Member Functions

 OnScopeExit (Callback &&callback)
 
 OnScopeExit (const OnScopeExit &)=delete
 
 OnScopeExit (OnScopeExit &&other)
 
 ~OnScopeExit ()
 
OnScopeExitoperator= (const OnScopeExit &)=delete
 

Detailed Description

template<typename Callback>
class agxUtil::OnScopeExit< Callback >

Register a callback to be called at the end of the current scope.

The callback may not throw exceptions, std::terminate may be called immediately if it does.

The callback should not take any parameters. The return value is ignored.

A factory function, onScopeExit, is provided to make OnScopeExit using lambdas possible.

Example usage:

void myFunction() { FILE* myFile = fopen(....); const auto& closeFile = onScopeExit([myFile]() { fclose(myFile); }); std::ignore = closeFile; std::ignore is used to prevent warning about unused variable.

The rest of the function goes here, possibly with early returns or exception throwing. }

Definition at line 53 of file OnScopeExit.h.

Constructor & Destructor Documentation

◆ OnScopeExit() [1/3]

template<typename Callback >
agxUtil::OnScopeExit< Callback >::OnScopeExit ( Callback &&  callback)
inline

Definition at line 56 of file OnScopeExit.h.

◆ OnScopeExit() [2/3]

template<typename Callback >
agxUtil::OnScopeExit< Callback >::OnScopeExit ( OnScopeExit< Callback > &&  other)
inline

Definition at line 61 of file OnScopeExit.h.

◆ OnScopeExit() [3/3]

template<typename Callback >
agxUtil::OnScopeExit< Callback >::OnScopeExit ( const OnScopeExit< Callback > &  )
delete

◆ ~OnScopeExit()

template<typename Callback >
agxUtil::OnScopeExit< Callback >::~OnScopeExit ( )
inline

Definition at line 69 of file OnScopeExit.h.

References LOGGER_ENDL, and LOGGER_ERROR.

Member Function Documentation

◆ operator=()

template<typename Callback >
OnScopeExit & agxUtil::OnScopeExit< Callback >::operator= ( const OnScopeExit< Callback > &  )
delete

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