Class Finalizer

Class Documentation

class Finalizer

Public Types

using FnType = void()
using FinalFn = std::function<FnType>

Public Static Functions

static void registerFunc(const FinalFn &fn)

Adds a function to be called at finalization. Functions are ordered last-in, first out.

Parameters:

fn – The function to be added. Must have void() signature.

static bool registerUnique(const FinalFn &fn)

Adds a function to be called at finalization unless it will already be called at finalization.

Adds a function in the same way as atfinal(), unless the function already exists in the list of functions to be called at finalization. Identity of functions is equality of the values of their target<void()>() member functions. Functions are ordered last-in, first out.

Parameters:

fn – The function to be added. Must have void() signature.

Returns:

true if the function was added, false if it already existed and was not added.

static bool contains(const FinalFn &fn)

Returns whether a function will already be called at finalization.

If the supplied function will already be called at finalization, return true, else return false. Identity of functions is equality of the values of their target<void()>() member functions.

Parameters:

fn – The function to be queried. Must have void() signature.

Returns:

true is the function is contained in those to be called at finalization, false if it is not.

static void finalize()

Runs the finalize functions and erases them.

In last-in, first-out order, the finalization functions are executed. If an exception is thrown, the throwing function will have been removed from the finalization functions, should execution be able to recover. If no exception is thrown, then there will be no finalization functions remaining. Otherwise, re-running finalize will begin execution with the function assigned previous to the one that threw the exception.

static size_t count()

Returns the number of finalize functions that will be run.

Returns:

the number of finalize functions that will be run.