finally.h File Reference

详细描述

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 manally (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(); };

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

◆  finally_opt

#define finally_opt
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
定义: memoryallocationbase.h:66
finally_once
#define finally_once
定义: finally.h:160