JUCE v8.0.9
JUCE API
 
Loading...
Searching...
No Matches
juce::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>

Inheritance diagram for juce::ScopeGuard< Fn >:
Collaboration diagram for juce::ScopeGuard< Fn >:

Public Member Functions

 ~ScopeGuard ()
 

Detailed Description

template<typename Fn>
struct juce::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:64

@tags{Core}

Constructor & Destructor Documentation

◆ ~ScopeGuard()

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

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