Loading...
Searching...
No Matches
juce::ErasedScopeGuard Class Reference

## Detailed Description

A ScopeGuard that uses a std::function internally to allow type erasure.

This can be handy; it allows lots of ErasedScopeGuards, all with different callbacks, to be stored in a homogeneous container.

An instance of this type will automatically call its callback when it is destroyed.

ErasedScopeGuard has a few similarities with std::unique_ptr:

- Calling reset() on a unique_ptr destroys the object if it hasn't been destroyed yet and puts the unique_ptr back into a default/null state; calling reset() on an ErasedScopeGuard calls the callback if it hasn't been called yet and puts the Guard back into a default/null state.
- Calling release() on a unique_ptr returns the unique_ptr back to a default state without destroying the managed object; calling release() on an ErasedScopeGuard returns the Guard back to a default state without calling the callback.
- Moving a unique_ptr transfers the responsibility of destroying the managed object to another unique_ptr instance; moving an ErasedScopeGuard transfers the responsibility of calling the callback to another Guard instance.

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

- juce_core/misc/juce_ScopeGuard.h

## Public Member Functions

| ErasedScopeGuard ()=default
| Constructs an ErasedScopeGuard with no callback.
| ErasedScopeGuard (std::function< void()> d)
| Constructs an ErasedScopeGuard that will call the provided callback when the Guard is destroyed.
| ErasedScopeGuard (ErasedScopeGuard &&other) noexcept
| Constructs an instance that assumes responsibility for calling other's callback.
ErasedScopeGuard & | operator= (ErasedScopeGuard &&other) noexcept
| Calls the stored callback, if any, then assumes responsibility for calling other's callback.
| ~ErasedScopeGuard () noexcept
| Destructor, calls the callback assigned to this ScopeGuard.
void | reset ()
| Calls the stored callback, if any, then resets this instance to its default state.
void | release ()
| Resets this instance to its default state without calling the stored callback.

## Constructors and Destructors

## ErasedScopeGuard() [1/3]

juce::ErasedScopeGuard::ErasedScopeGuard | ( |  | ) |

default

Constructs an ErasedScopeGuard with no callback.

Referenced by ErasedScopeGuard(), operator=(), and release().

## ErasedScopeGuard() [2/3]

juce::ErasedScopeGuard::ErasedScopeGuard | ( | std::function< void()> | d | ) |

explicit

Constructs an ErasedScopeGuard that will call the provided callback when the Guard is destroyed.

## ErasedScopeGuard() [3/3]

juce::ErasedScopeGuard::ErasedScopeGuard | ( | ErasedScopeGuard && | other | ) |

noexcept

Constructs an instance that assumes responsibility for calling other's callback.

References ErasedScopeGuard().

## ~ErasedScopeGuard()

juce::ErasedScopeGuard::~ErasedScopeGuard | ( |  | ) |

noexcept

Destructor, calls the callback assigned to this ScopeGuard.

## Member Functions

## operator=()

ErasedScopeGuard & juce::ErasedScopeGuard::operator= | ( | ErasedScopeGuard && | other | ) |

noexcept

Calls the stored callback, if any, then assumes responsibility for calling other's callback.

After this call, other will be reset to its default state.

References ErasedScopeGuard().

## reset()

void juce::ErasedScopeGuard::reset | ( |  | ) |

Calls the stored callback, if any, then resets this instance to its default state.

References reset().

Referenced by reset().

## release()

void juce::ErasedScopeGuard::release | ( |  | ) |

Resets this instance to its default state without calling the stored callback.

References ErasedScopeGuard(), JUCE_DECLARE_NON_COPYABLE, and release().

Referenced by release().

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited