Open Search
    finally.h File Reference

    Detailed Description

    The finally macro.

    Classes

    class  FinallyWrapper< T >
     
    class  FinallyFactory
     
    class  FinallyOnce< T >
     
    class  FinallyOnceFactory
     

    Namespaces

     maxon
     
     maxon::details
     

    Macros

    #define finally
     
    #define finally_once
     
    #define finally_opt
     

    Macro Definition Documentation

    ◆ finally

    #define finally

    Use this to specify a code block which shall be executed when the current scope is left. If you want to execute the finally statement manually (or disable it) see finally_once.

    {
    finally { _initializing = false; };
    _initializing = true;
    ...
    // _initializing will be reset to false at this point, even if the block is left by a return statement.
    };

    The code block is part of a lambda expression which captures all variables by reference.

    ◆ finally_once

    #define finally_once

    Use finally_once for a code block which shall be executed when the current scope is left or might be invoked manually (to clean up). In any case the block is invoked just once (unless it is manually disabled).

    {
    auto cleanup = finally_once { return Cleanup(); };
    if (!YourCheck())
    return IllegalArgumentError(MAXON_SOURCE_LOCATION);
    if (IsVerySpecialCaseWhichMustNotExecuteCleanup())
    {
    cleanup.Disable();
    return VerySpecialCaseError(MAXON_SOURCE_LOCATION);
    }
    return cleanup();
    };
    #define finally_once
    Definition: finally.h:158
    #define MAXON_SOURCE_LOCATION
    Definition: memoryallocationbase.h:69

    The code block is part of a lambda expression which captures all variables by reference.

    ◆ finally_opt

    #define finally_opt