avcpp 3.2.1
Wrapper for the FFmpeg that simplify usage from C++ projects.
Loading...
Searching...
No Matches
av::ScopeOutAction Class Reference

The ScopeOutAction class - guard-type class that allows points callback that will be called at the scope out. More...

#include <avutils.h>

Public Member Functions

template<typename Proc>
 ScopeOutAction (const Proc &proc)
 Run a callback when the guard leaves scope.
template<typename Proc>
 ScopeOutAction (Proc &&proc)
 Run a callback when the guard leaves scope, moving it in.

Detailed Description

Example:

void foo()
{
int fd = open(...some args...);
ScopeOutAction action([fd](){
close(fd);
});
try
{
// some actions that can throw exception
}
catch(...)
{
throw; // Not best-practice, only for example
}
}
ScopeOutAction(const Proc &proc)
Run a callback when the guard leaves scope.
Definition avutils.h:479

In example above dtor of the action will be called before fd and we correctly close descriptor.

Constructor & Destructor Documentation

◆ ScopeOutAction() [1/2]

template<typename Proc>
av::ScopeOutAction::ScopeOutAction ( const Proc & proc)
inline
Template Parameters
Proccallable type
Parameters
procthe callback to invoke; it is copied into the guard

◆ ScopeOutAction() [2/2]

template<typename Proc>
av::ScopeOutAction::ScopeOutAction ( Proc && proc)
inline
Template Parameters
Proccallable type
Parameters
procthe callback to invoke; it is moved into the guard

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