Loading...
Searching...
No Matches
Public Member Functions | List of all members
ScopeGuard< Fn > Struct Template Reference

An easy way to ensure that a function is called at the end of the current scope. More...

#include <juce_ScopeGuard.h>

Inherits Fn.

Public Member Functions

 ~ScopeGuard ()
 

Detailed Description

template<typename Fn>
struct ScopeGuard< Fn >

An easy way to ensure that a function is called at the end of the current scope.

Usage:

{
if (flag == true)
return;
// While this code executes, flag is true e.g. to prevent reentrancy
flag = true;
// When we exit this scope, flag must be false
const ScopeGuard scope { [&] { flag = false; } };
if (checkInitialCondition())
return; // Scope's lambda will fire here...
if (checkCriticalCondition())
throw std::runtime_error{}; // ...or here...
doWorkHavingEstablishedPreconditions();
} // ...or here!
An easy way to ensure that a function is called at the end of the current scope.
Definition juce_ScopeGuard.h:55

Constructor & Destructor Documentation

◆ ~ScopeGuard()

template<typename Fn >
ScopeGuard< Fn >::~ScopeGuard ( )

The documentation for this struct was generated from the following file:
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram