99 lines
13 KiB
HTML
99 lines
13 KiB
HTML
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
|
|
<title>Macro BOOST_SCOPE_EXIT</title>
|
|
<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
|
|
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
|
|
<link rel="home" href="index.html" title="Chapter 1. Boost.ScopeExit 1.1.0">
|
|
<link rel="up" href="reference.html#header.boost.scope_exit_hpp" title="Header <boost/scope_exit.hpp>">
|
|
<link rel="prev" href="reference.html" title="Reference">
|
|
<link rel="next" href="BOOST_SCOPE_EXIT_TPL.html" title="Macro BOOST_SCOPE_EXIT_TPL">
|
|
</head>
|
|
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
|
<table cellpadding="2" width="100%"><tr>
|
|
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td>
|
|
<td align="center"><a href="../../../../index.html">Home</a></td>
|
|
<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
|
|
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
|
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
|
<td align="center"><a href="../../../../more/index.htm">More</a></td>
|
|
</tr></table>
|
|
<hr>
|
|
<div class="spirit-nav">
|
|
<a accesskey="p" href="reference.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="reference.html#header.boost.scope_exit_hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="BOOST_SCOPE_EXIT_TPL.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
|
|
</div>
|
|
<div class="refentry">
|
|
<a name="BOOST_SCOPE_EXIT"></a><div class="titlepage"></div>
|
|
<div class="refnamediv">
|
|
<h2><span class="refentrytitle">Macro BOOST_SCOPE_EXIT</span></h2>
|
|
<p>BOOST_SCOPE_EXIT — This macro declares a scope exit. </p>
|
|
</div>
|
|
<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
|
|
<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: <<a class="link" href="reference.html#header.boost.scope_exit_hpp" title="Header <boost/scope_exit.hpp>">boost/scope_exit.hpp</a>>
|
|
|
|
</span>BOOST_SCOPE_EXIT(capture_list)</pre></div>
|
|
<div class="refsect1">
|
|
<a name="id875870"></a><h2>Description</h2>
|
|
<p>The scope exit declaration schedules the execution of the scope exit body at the exit of the enclosing scope:</p>
|
|
<pre class="programlisting"><span class="special">{</span> <span class="comment">// Some local scope.</span>
|
|
<span class="special">...</span>
|
|
<span class="identifier">BOOST_SCOPE_EXIT</span><span class="special">(</span><span class="identifier">capture_list</span><span class="special">)</span> <span class="special">{</span>
|
|
<span class="special">...</span> <span class="comment">// Body code.</span>
|
|
<span class="special">}</span> <span class="identifier">BOOST_SCOPE_EXIT_END</span>
|
|
<span class="special">...</span>
|
|
<span class="special">}</span>
|
|
</pre>
|
|
<p>The enclosing scope must be local. If multiple scope exits are declared within the same enclosing scope, the scope exit bodies are executed in the reversed order of their declarations. Note how the end of the scope exit body must be marked by <code class="computeroutput"><a class="link" href="BOOST_SCOPE_EXIT_END.html" title="Macro BOOST_SCOPE_EXIT_END">BOOST_SCOPE_EXIT_END</a></code>.</p>
|
|
<p><span class="bold"><strong>Parameters:</strong></span> </p>
|
|
<div class="informaltable"><table class="table">
|
|
<colgroup>
|
|
<col>
|
|
<col>
|
|
</colgroup>
|
|
<tbody><tr>
|
|
<td><span class="bold"><strong><code class="computeroutput">capture_list</code></strong></span></td>
|
|
<td>On compilers that support variadic macros (see also Boost.Config <code class="computeroutput">BOOST_NO_CXX11_VARIADIC_MACROS</code>), the capture list syntax is defined by the following grammar: <pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">capture_list</span><span class="special">:</span>
|
|
<span class="keyword">void</span> <span class="special">|</span> <span class="identifier">capture_tuple</span> <span class="special">|</span> <span class="identifier">capture_sequence</span>
|
|
<span class="identifier">capture_tuple</span><span class="special">:</span>
|
|
<span class="identifier">capture</span><span class="special">,</span> <span class="identifier">capture</span><span class="special">,</span> <span class="special">...</span>
|
|
<span class="identifier">capture_sequence</span><span class="special">:</span>
|
|
<span class="special">(</span><span class="identifier">capture</span><span class="special">)</span> <span class="special">(</span><span class="identifier">capture</span><span class="special">)</span> <span class="special">...</span>
|
|
<span class="identifier">capture</span><span class="special">:</span>
|
|
<span class="special">[</span><span class="special">&</span><span class="special">]</span><span class="identifier">variable</span> <span class="special">|</span> <span class="identifier">this_</span>
|
|
</pre> On compilers that do not support variadic macros, <code class="computeroutput">capture_tuple</code> cannot be used: <pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">capture_list</span><span class="special">:</span>
|
|
<span class="keyword">void</span> <span class="special">|</span> <span class="identifier">capture_sequence</span>
|
|
</pre> Furthermore, if <code class="computeroutput"><a class="link" href="BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS.html" title="Macro BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS">BOOST_SCOPE_EXIT_CONFIG_USE_LAMBDAS</a></code> is defined on C++11 compilers that support lambda functions (i.e., Boost.Config's <code class="computeroutput">BOOST_NO_CXX11_LAMBDAS</code> is not defined) then a semicolon <code class="computeroutput">;</code> can be used instead of <code class="computeroutput"><a class="link" href="BOOST_SCOPE_EXIT_END.html" title="Macro BOOST_SCOPE_EXIT_END">BOOST_SCOPE_EXIT_END</a></code> and <code class="computeroutput">this</code> can be used instead of <code class="computeroutput">this_</code>: <pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">capture</span><span class="special">:</span>
|
|
<span class="special">[</span><span class="special">&</span><span class="special">]</span><span class="identifier">variable</span> <span class="special">|</span> <span class="identifier">this_</span> <span class="special">|</span> <span class="keyword">this</span>
|
|
</pre>(Lexical conventions: <code class="computeroutput">token1 | token2</code> means either <code class="computeroutput">token1</code> or <code class="computeroutput">token2</code>; <code class="computeroutput">[token]</code> means either <code class="computeroutput">token</code> or nothing; <code class="computeroutput">{expression}</code> means the tokens resulting from the expression.) </td>
|
|
</tr></tbody>
|
|
</table></div>
|
|
<p>
|
|
</p>
|
|
<p>Note that on compilers that support variadic macros (most of moder compliers and all C++11 compilers), the capture list can be specified as a comma-separated list of tokens (this is the preferred syntax). However, on all compilers the same macro <code class="computeroutput"><a class="link" href="BOOST_SCOPE_EXIT.html" title="Macro BOOST_SCOPE_EXIT">BOOST_SCOPE_EXIT</a></code> also allows to specify the capture list as a Boost.Preprocessor sequence of tokens (for supporting compilers without variadic macros and for backward compatibility with older versions of this library).</p>
|
|
<p>The name <code class="computeroutput">variable</code> of each captured variable must be a valid name in the enclosing scope and it must appear exactly once in the capture list. If a capture starts with the ampersand sign <code class="computeroutput">&</code>, the corresponding variable will be available by reference within the scope exit body; otherwise, a copy of the variable will be made at the point of the scope exit declaration and that copy will be available inside the scope exit body (in this case, the variable's type must be <code class="computeroutput">CopyConstructible</code>).</p>
|
|
<p>From within a member function, the object <code class="computeroutput">this</code> can be captured using the special name <code class="computeroutput">this_</code> in both the capture list and the scope exit body (using <code class="computeroutput">this</code> instead of <code class="computeroutput">this_</code> in the scope exit body leads to undefined behaviour).</p>
|
|
<p>It is possible to capture no variable by specifying the capture list as <code class="computeroutput">void</code> (regardless of variadic macro support).</p>
|
|
<p>Only variables listed in the capture list, static variables, <code class="computeroutput">extern</code> variables, global variables, functions, and enumerations from the enclosing scope can be used inside the scope exit body.</p>
|
|
<p>On various GCC versions the special macro <code class="computeroutput"><a class="link" href="BOOST_SCOPE_EXIT_TPL.html" title="Macro BOOST_SCOPE_EXIT_TPL">BOOST_SCOPE_EXIT_TPL</a></code> must be used instead of <code class="computeroutput"><a class="link" href="BOOST_SCOPE_EXIT.html" title="Macro BOOST_SCOPE_EXIT">BOOST_SCOPE_EXIT</a></code> within templates (to maximize portability, it is recommended to always use <code class="computeroutput"><a class="link" href="BOOST_SCOPE_EXIT_TPL.html" title="Macro BOOST_SCOPE_EXIT_TPL">BOOST_SCOPE_EXIT_TPL</a></code> within templates).</p>
|
|
<p>On C++11, it is possible capture all variables in scope without listing their names one-by-one using the macro <code class="computeroutput"><a class="link" href="BOOST_SCOPE_EXIT_ALL.html" title="Macro BOOST_SCOPE_EXIT_ALL">BOOST_SCOPE_EXIT_ALL</a></code>.</p>
|
|
<p>In general, the special macro <code class="computeroutput"><a class="link" href="BOOST_SCOPE_EXIT_ID.html" title="Macro BOOST_SCOPE_EXIT_ID">BOOST_SCOPE_EXIT_ID</a></code> must be used instead of <code class="computeroutput"><a class="link" href="BOOST_SCOPE_EXIT.html" title="Macro BOOST_SCOPE_EXIT">BOOST_SCOPE_EXIT</a></code> when it is necessary to expand multiple scope exit declarations on the same line.</p>
|
|
<p><span class="bold"><strong>Warning:</strong></span> The implementation executes the scope exit body within a destructor thus the scope exit body must never throw in order to comply with STL exception safety requirements.</p>
|
|
<p><span class="bold"><strong>Note:</strong></span> The implementation uses Boost.Typeof to automatically deduce the types of the captured variables. In order to compile code in type-of emulation mode, all types must be properly registered with Boost.Typeof (see the <a class="link" href="scope_exit/getting_started.html" title="Getting Started"> Getting Started</a> section).</p>
|
|
<p><span class="bold"><strong>See:</strong></span> <a class="link" href="scope_exit/tutorial.html" title="Tutorial"> Tutorial</a> section, <a class="link" href="scope_exit/getting_started.html" title="Getting Started"> Getting Started</a> section, <a class="link" href="scope_exit/no_variadic_macros.html" title="Annex: No Variadic Macros"> No Variadic Macros</a> section, <code class="computeroutput"><a class="link" href="BOOST_SCOPE_EXIT_TPL.html" title="Macro BOOST_SCOPE_EXIT_TPL">BOOST_SCOPE_EXIT_TPL</a></code>, <code class="computeroutput"><a class="link" href="BOOST_SCOPE_EXIT_ALL.html" title="Macro BOOST_SCOPE_EXIT_ALL">BOOST_SCOPE_EXIT_ALL</a></code>, <code class="computeroutput"><a class="link" href="BOOST_SCOPE_EXIT_END.html" title="Macro BOOST_SCOPE_EXIT_END">BOOST_SCOPE_EXIT_END</a></code>, <code class="computeroutput"><a class="link" href="BOOST_SCOPE_EXIT_ID.html" title="Macro BOOST_SCOPE_EXIT_ID">BOOST_SCOPE_EXIT_ID</a></code>. </p>
|
|
</div>
|
|
</div>
|
|
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
|
<td align="left"></td>
|
|
<td align="right"><div class="copyright-footer">Copyright © 2006-2012 Alexander Nasonov, Lorenzo Caminiti<p>
|
|
Distributed under the Boost Software License, Version 1.0 (see accompanying
|
|
file LICENSE_1_0.txt or a copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
|
|
</p>
|
|
</div></td>
|
|
</tr></table>
|
|
<hr>
|
|
<div class="spirit-nav">
|
|
<a accesskey="p" href="reference.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="reference.html#header.boost.scope_exit_hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="BOOST_SCOPE_EXIT_TPL.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
|
|
</div>
|
|
</body>
|
|
</html>
|