Back to Arangodb

Chapter 1. Boost.ScopeExit 1.1.0

3rdParty/boost/1.78.0/libs/scope_exit/doc/html/index.html

3.12.9.12.6 KB
Original Source

| | Home | Libraries | People | FAQ | More |


Chapter 1. Boost.ScopeExit 1.1.0

Alexander Nasonov

Lorenzo Caminiti <[email protected]>

Copyright © 2006-2012 Alexander Nasonov, Lorenzo Caminiti

Distributed under the Boost Software License, Version 1.0 (see accompanying file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt)

This library allows to execute arbitrary code when the enclosing scope exits.

Introduction

Nowadays, every C++ developer is familiar with the Resource Acquisition Is Initialization (RAII) technique. It binds resource acquisition and release to initialization and destruction of a variable that holds the resource. There are times when writing a special class for such a variable is not worth the effort. This is when Boost.ScopeExit comes into play.

Programmers can put resource acquisition directly in their code and next to it, they can write code that releases the resource using this library. For example (see also world.cpp): [1]

voidworld::add\_person(personconst&a\_person){boolcommit=false;persons\_.push\_back(a\_person);// (1) direct action// Following block is executed when the enclosing scope exits.BOOST\_SCOPE\_EXIT(&commit,&persons\_){if(!commit)persons\_.pop\_back();// (2) rollback action}BOOST\_SCOPE\_EXIT\_END// ... // (3) other operationscommit=true;// (4) disable rollback actions}

[1] Older versions of this library used a Boost.Preprocessor sequence to specify the list of captured variables. While maintaining full backward compatibility, it is now possible to specify the captured variables also using a comma-separated list (which is the preferred syntax). See the No Variadic Macros section for more information.

|

Last revised: December 02, 2021 at 06:49:40 GMT

|

|