JUCE: ScopeGuard< Fn > Struct Template Reference

JUCE

- Main Page
- Related Pages
- Topics
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

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

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!
ScopeGuard
An easy way to ensure that a function is called at the end of the current scope.
Definition juce_ScopeGuard.h:53

## Constructor & Destructor Documentation

## ◆ ~ScopeGuard()

template<typename Fn >

ScopeGuard< Fn >::~ScopeGuard | ( |  | ) |

References ScopeGuard< Fn >::~ScopeGuard().

Referenced by ScopeGuard< Fn >::~ScopeGuard().

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

- juce_ScopeGuard.h