Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r76623 - in sandbox/closure/libs/local_function/doc/html: . boost_localfunction
From: lorcaminiti_at_[hidden]
Date: 2012-01-21 13:28:38


Author: lcaminiti
Date: 2012-01-21 13:28:36 EST (Sat, 21 Jan 2012)
New Revision: 76623
URL: http://svn.boost.org/trac/boost/changeset/76623

Log:
Examples, tests, and docs.
Added:
   sandbox/closure/libs/local_function/doc/html/
   sandbox/closure/libs/local_function/doc/html/boost_localfunction/
   sandbox/closure/libs/local_function/doc/html/boost_localfunction/Acknowledgments.html (contents, props changed)
   sandbox/closure/libs/local_function/doc/html/boost_localfunction/Advanced_Topics.html (contents, props changed)
   sandbox/closure/libs/local_function/doc/html/boost_localfunction/Alternatives.html (contents, props changed)
   sandbox/closure/libs/local_function/doc/html/boost_localfunction/Bibliography.html (contents, props changed)
   sandbox/closure/libs/local_function/doc/html/boost_localfunction/Examples.html (contents, props changed)
   sandbox/closure/libs/local_function/doc/html/boost_localfunction/Getting_Started.html (contents, props changed)
   sandbox/closure/libs/local_function/doc/html/boost_localfunction/Implementation.html (contents, props changed)
   sandbox/closure/libs/local_function/doc/html/boost_localfunction/No_Variadic_Macros.html (contents, props changed)
   sandbox/closure/libs/local_function/doc/html/boost_localfunction/Release_Notes.html (contents, props changed)
   sandbox/closure/libs/local_function/doc/html/boost_localfunction/Tutorial.html (contents, props changed)
   sandbox/closure/libs/local_function/doc/html/index.html (contents, props changed)

Added: sandbox/closure/libs/local_function/doc/html/boost_localfunction/Acknowledgments.html
==============================================================================
--- (empty file)
+++ sandbox/closure/libs/local_function/doc/html/boost_localfunction/Acknowledgments.html 2012-01-21 13:28:36 EST (Sat, 21 Jan 2012)
@@ -0,0 +1,96 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
+<title>Acknowledgments</title>
+<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
+<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;Boost.LocalFunction 1.0.0">
+<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;Boost.LocalFunction 1.0.0">
+<link rel="prev" href="Bibliography.html" title="Bibliography">
+</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">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="Bibliography.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><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>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_localfunction.Acknowledgments"></a><a class="link" href="Acknowledgments.html" title="Acknowledgments">Acknowledgments</a>
+</h2></div></div></div>
+<p>
+ This section attempts to recognize the contributions of <span class="emphasis"><em>all</em></span>
+ the different people that participated directly or indirectly to the design
+ and development of this library.
+ </p>
+<p>
+ Many thanks to Steven Watanabe and Vicente Botet for suggesting to me to use
+ Boost.ScopeExit
+ binding to <a href="http://boost.2283326.n4.nabble.com/contract-diff-n1962-tt2671482.html#none" target="_top">emulate
+ local functions</a>. Many thanks to Alexander Nasonov for clarifying how
+ Boost.ScopeExit
+ binding could be used to implement local functions and for some <a href="http://thread.gmane.org/gmane.comp.lib.boost.devel/168612" target="_top">early
+ work</a> in this direction.
+ </p>
+<p>
+ Many thanks to Gregory Crosswhite for using an early version of this library
+ in one of his projects.
+ </p>
+<p>
+ Thanks to David Abrahams, Vicente Botet, et al. for suggesting to provide the
+ <a href="http://lists.boost.org/Archives/boost/2011/02/176712.php" target="_top">variadic
+ macro syntax</a> on compilers that support variadic macros.
+ </p>
+<p>
+ Thanks to Pierre Morcello for suggesting to use <code class="computeroutput"><span class="keyword">return</span><span class="special">;</span></code> to exit local blocks (in the context of a
+ discussion about a possible Boost.Breakable
+ library). Thanks to Pierre also for sharing some code that experimented with
+ implementing local functions using Boost.ScopeExit
+ binding (even if this library was not developed using such a code).
+ </p>
+<p>
+ Thanks to John Bytheway for checking the authors' virtual functor technique
+ that originally allowed this library to pass local functions as template parameters.
+ </p>
+<p>
+ Thanks to Jeffrey Lee Hellrung for suggesting the use of the "keyword"
+ <code class="computeroutput"><span class="identifier">bind</span></code> to bind variables in scope
+ and for suggesting to use <code class="literal">bind(<span class="emphasis"><em>type</em></span>)</code>
+ to optionally specify the bound variable type. Thanks to Vicente Botet for
+ suggesting to provide a macro to expose the bound variable type to the public
+ API.
+ </p>
+<p>
+ Thanks to Steven Watanabe, Vicente Botet, Michael Caisse, Yechezkel Mett, Joel
+ de Guzman, Thomas Heller, et al. for helping with the <a class="link" href="../">Alternatives</a>
+ section and with the profiling of the different alternatives.
+ </p>
+<p>
+ Finally, many thanks to the entire Boost
+ community and mailing list for
+ providing valuable comments about this library and great insights on the C++
+ programming language.
+ </p>
+</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 &#169; 2009-2012 Lorenzo
+ Caminiti<p>
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="Bibliography.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><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>
+</div>
+</body>
+</html>

Added: sandbox/closure/libs/local_function/doc/html/boost_localfunction/Advanced_Topics.html
==============================================================================
--- (empty file)
+++ sandbox/closure/libs/local_function/doc/html/boost_localfunction/Advanced_Topics.html 2012-01-21 13:28:36 EST (Sat, 21 Jan 2012)
@@ -0,0 +1,1241 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
+<title>Advanced Topics</title>
+<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
+<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;Boost.LocalFunction 1.0.0">
+<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;Boost.LocalFunction 1.0.0">
+<link rel="prev" href="Tutorial.html" title="Tutorial">
+<link rel="next" href="Examples.html" title="Appendix: Examples">
+</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">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="Tutorial.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><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="Examples.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_localfunction.Advanced_Topics"></a><a class="link" href="Advanced_Topics.html" title="Advanced Topics">Advanced Topics</a>
+</h2></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"><a href="Advanced_Topics.html#boost_localfunction.Advanced_Topics.default_parameters">Default
+ Parameters</a></span></dt>
+<dt><span class="section"><a href="Advanced_Topics.html#boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros">Commas
+ and Symbols in Macros</a></span></dt>
+<dt><span class="section"><a href="Advanced_Topics.html#boost_localfunction.Advanced_Topics.assigning_and_returning">Assigning
+ and Returning</a></span></dt>
+<dt><span class="section">Nesting</span></dt>
+<dt><span class="section"><a href="Advanced_Topics.html#boost_localfunction.Advanced_Topics.deducing_bound_types__concepts__etc_">Deducing
+ Bound Types (concepts, etc)</a></span></dt>
+<dt><span class="section"><a href="Advanced_Topics.html#boost_localfunction.Advanced_Topics.specifying_types">Specifying
+ Types</a></span></dt>
+<dt><span class="section">Inlining</span></dt>
+<dt><span class="section">Recursion</span></dt>
+<dt><span class="section">Overloading</span></dt>
+<dt><span class="section"><a href="Advanced_Topics.html#boost_localfunction.Advanced_Topics.exception_specifications">Exception
+ Specifications</a></span></dt>
+<dt><span class="section"><a href="Advanced_Topics.html#boost_localfunction.Advanced_Topics.storage_classifiers___auto__and__register__">Storage
+ Classifiers (<code class="computeroutput"><span class="keyword">auto</span></code> and <code class="computeroutput"><span class="keyword">register</span></code>)</a></span></dt>
+<dt><span class="section"><a href="Advanced_Topics.html#boost_localfunction.Advanced_Topics.limitations__operators__etc_">Limitations
+ (operators, etc)</a></span></dt>
+</dl></div>
+<p>
+ This section illustrates advanced usages of this library. At the end of this
+ section there is also a list of knwon limitations of this library.
+ </p>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Advanced_Topics.default_parameters"></a><a class="link" href="Advanced_Topics.html#boost_localfunction.Advanced_Topics.default_parameters" title="Default Parameters">Default
+ Parameters</a>
+</h3></div></div></div>
+<p>
+ This library also allows to specify default values for the local function
+ parameters. However, the usual C++ syntax for default parameters that uses
+ the assignment symbol <code class="computeroutput"><span class="special">=</span></code> cannot
+ be used. <sup>[<a name="boost_localfunction.Advanced_Topics.default_parameters.f0" href="#ftn.boost_localfunction.Advanced_Topics.default_parameters.f0" class="footnote">15</a>]</sup> The keyword <code class="computeroutput"><span class="keyword">default</span></code>
+ is used instead:
+ </p>
+<pre class="programlisting"><code class="literal"><span class="emphasis"><em>parameter-type parameter-name</em></span></code><span class="special">,</span> <span class="keyword">default</span> <code class="literal"><span class="emphasis"><em>parameter-default-value</em></span></code><span class="special">,</span> <span class="special">...</span>
+</pre>
+<p>
+ For example, let's program a local function <code class="computeroutput"><span class="identifier">add</span><span class="special">(</span><span class="identifier">x</span><span class="special">,</span>
+ <span class="identifier">y</span><span class="special">)</span></code>
+ where the second parameter <code class="computeroutput"><span class="identifier">y</span></code>
+ is optional and has a default value of <code class="computeroutput"><span class="number">2</span></code>
+ (see also "add_default.cpp"):
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">y</span><span class="special">,</span> <span class="keyword">default</span> <span class="number">2</span><span class="special">)</span> <span class="special">{</span> <span class="comment">// Default.</span>
+ <span class="keyword">return</span> <span class="identifier">x</span> <span class="special">+</span> <span class="identifier">y</span><span class="special">;</span>
+<span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">add</span><span class="special">)</span>
+
+<span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">add</span><span class="special">(</span><span class="number">1</span><span class="special">)</span> <span class="special">==</span> <span class="number">3</span> <span class="special">);</span>
+</pre>
+<p>
+ </p>
+<p>
+ Programmers can define a <code class="computeroutput"><span class="identifier">WITH_DEFAULT</span></code>
+ macro similar to the following if they think it improves readability over
+ the syntax above (see also "add_with_default.cpp"):
+ <sup>[<a name="boost_localfunction.Advanced_Topics.default_parameters.f1" href="#ftn.boost_localfunction.Advanced_Topics.default_parameters.f1" class="footnote">16</a>]</sup>
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="preprocessor">#define</span> <span class="identifier">WITH_DEFAULT</span> <span class="special">,</span> <span class="keyword">default</span>
+</pre>
+<p>
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">y</span> <span class="identifier">WITH_DEFAULT</span> <span class="number">2</span><span class="special">)</span> <span class="special">{</span> <span class="comment">// Default.</span>
+ <span class="keyword">return</span> <span class="identifier">x</span> <span class="special">+</span> <span class="identifier">y</span><span class="special">;</span>
+<span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">add</span><span class="special">)</span>
+
+<span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">add</span><span class="special">(</span><span class="number">1</span><span class="special">)</span> <span class="special">==</span> <span class="number">3</span> <span class="special">);</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros"></a><a class="link" href="Advanced_Topics.html#boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros" title="Commas and Symbols in Macros">Commas
+ and Symbols in Macros</a>
+</h3></div></div></div>
+<p>
+ The C++ preprocessor does not allow commas <code class="computeroutput"><span class="special">,</span></code>
+ within macro parameters unless they are wrapped by round parenthesis <code class="computeroutput"><span class="special">()</span></code>. Therefore, using commas within the local
+ function parameters and bindings will generate (cryptic) preprocessor errors
+ unless they are wrapped with an extra set of round parenthesis <code class="computeroutput"><span class="special">()</span></code> as explained here.
+ </p>
+<div class="note"><table border="0" summary="Note">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../doc/src/images/note.png"></td>
+<th align="left">Note</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ Macro parameters with commas which are already wrapped by round parenthesis
+ <code class="computeroutput"><span class="special">()</span></code> are fine (function calls,
+ etc). However, macro parameters with commas that are not wrapped by round
+ parenthesis need to be wrapped by an extra set of round parenthesis <code class="computeroutput"><span class="special">()</span></code> as described here. Also macro parameters
+ with commas wrapped by angular parenthesis <code class="computeroutput"><span class="special">&lt;&gt;</span></code>
+ (templates, etc) or square parenthesis <code class="computeroutput"><span class="special">[]</span></code>
+ (multidimensional array access, etc) need to be wrapped by the extra round
+ parenthesis <code class="computeroutput"><span class="special">()</span></code> as explained
+ here (this is because the preprocessor only recognizes the round parenthesis
+ and it does not recognize angular, square, or any other type of parenthesis).
+ </p></td></tr>
+</table></div>
+<p>
+ In addition, local function parameter types cannot start with non-alphanumeric
+ symbols (alphanumeric symbols are <code class="computeroutput"><span class="identifier">A</span><span class="special">-</span><span class="identifier">Z</span></code>, <code class="computeroutput"><span class="identifier">a</span><span class="special">-</span><span class="identifier">z</span></code>,
+ and <code class="computeroutput"><span class="number">0</span><span class="special">-</span><span class="number">9</span></code>). <sup>[<a name="boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f0" href="#ftn.boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f0" class="footnote">17</a>]</sup> The library will generate (cryptic) preprocessor errors if a
+ parameter type starts with a non-alphanumeric symbol.
+ </p>
+<p>
+ Let's consider the following example:
+ </p>
+<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span>
+ <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">map</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <span class="identifier">size_t</span><span class="special">&gt;&amp;</span> <span class="identifier">m</span><span class="special">,</span> <span class="comment">// (1) Error.</span>
+ <span class="special">::</span><span class="identifier">sign_t</span> <span class="identifier">sign</span><span class="special">,</span> <span class="comment">// (2) Error.</span>
+ <span class="keyword">const</span> <span class="identifier">size_t</span><span class="special">&amp;</span> <span class="identifier">factor</span><span class="special">,</span> <span class="keyword">default</span>
+ <span class="identifier">key_size</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <span class="identifier">size_t</span><span class="special">&gt;::</span><span class="identifier">value</span><span class="special">,</span> <span class="comment">// (3) Error.</span>
+ <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&amp;</span> <span class="identifier">separator</span><span class="special">,</span> <span class="keyword">default</span> <span class="identifier">cat</span><span class="special">(</span><span class="string">":"</span><span class="special">,</span> <span class="string">" "</span><span class="special">)</span> <span class="comment">// (4) OK.</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="special">...</span>
+<span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">f</span><span class="special">)</span>
+</pre>
+<p>
+ <span class="bold"><strong>(1)</strong></span> The parameter type <code class="computeroutput"><span class="keyword">const</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">map</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <span class="identifier">size_t</span><span class="special">&gt;&amp;</span></code> contains a comma <code class="computeroutput"><span class="special">,</span></code>
+ after the first template parameter <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span></code>.
+ This comma is not wrapped by any round parenthesis <code class="computeroutput"><span class="special">()</span></code>
+ thus it will cause a preprocessor error. The Boost.Utility
+ macro <code class="computeroutput"><span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">(</span></code><span class="emphasis"><em>parenthesized-type</em></span><code class="computeroutput"><span class="special">)</span></code> from the header <code class="computeroutput"><span class="string">"boost/utility/identity_type.hpp"</span></code>
+ can be used to wrap a type within extra parenthesis <code class="computeroutput"><span class="special">()</span></code>
+ so to overcome this issue:
+ </p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">utility</span><span class="special">/</span><span class="identifier">identity_type</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span>
+ <span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">((</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">map</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <span class="identifier">size_t</span><span class="special">&gt;&amp;))</span> <span class="identifier">m</span><span class="special">,</span> <span class="comment">// OK.</span>
+ <span class="special">...</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="special">...</span>
+<span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">f</span><span class="special">)</span>
+</pre>
+<p>
+ This macro expands to an expression that evaluates (at compile-time) exactly
+ to the specified type. Note that a total of two set of parenthesis <code class="computeroutput"><span class="special">()</span></code> are needed: The parenthesis to invoke the
+ <code class="computeroutput"><span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">(..)</span></code>
+ macro plus the parenthesis to wrap the type expression (and therefore any
+ comma <code class="computeroutput"><span class="special">,</span></code> that it contains) passed
+ as parameter to the <code class="computeroutput"><span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">((...)</span></code> macro. <sup>[<a name="boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f1" href="#ftn.boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f1" class="footnote">18</a>]</sup> Finally, the <code class="computeroutput"><span class="identifier">BOOST_IDENTITY_TYPE</span></code>
+ macro must be prefixed by the <code class="computeroutput"><span class="keyword">typename</span></code>
+ keyword as in <code class="computeroutput"><span class="keyword">typename</span> <span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">(</span></code><span class="emphasis"><em>parenthesized-type</em></span><code class="computeroutput"><span class="special">)</span></code> when used within <code class="computeroutput">BOOST_LOCAL_FUNCTION_TPL</code>
+ for templates.
+ </p>
+<div class="note"><table border="0" summary="Note">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../doc/src/images/note.png"></td>
+<th align="left">Note</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ Often, there might be better ways to overcome this limitation that lead
+ to code which is more readable than the one using the <code class="computeroutput"><span class="identifier">BOOST_IDENTITY_TYPE</span></code>
+ macro. For example, in this case a <code class="computeroutput"><span class="keyword">typedef</span></code>
+ could have been used in the enclosing scope to obtain the following valid
+ and perhaps more readable code:
+ </p></td></tr>
+</table></div>
+<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">map</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <span class="identifier">size_t</span><span class="special">&gt;</span> <span class="identifier">map_type</span><span class="special">;</span>
+<span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span>
+ <span class="keyword">const</span> <span class="identifier">map_type</span><span class="special">&amp;</span> <span class="identifier">m</span><span class="special">,</span> <span class="comment">// OK.</span>
+ <span class="special">...</span>
+<span class="special">)</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">f</span><span class="special">)</span>
+</pre>
+<p>
+ <span class="bold"><strong>(2)</strong></span> The parameter type <code class="computeroutput"><span class="special">::</span><span class="identifier">sign_t</span></code> starts with the non-alphanumeric
+ symbols <code class="computeroutput"><span class="special">::</span></code> thus it will generate
+ preprocessor errors if used as a local function parameter type. The macros
+ <code class="computeroutput"><span class="identifier">BOOST_IDENTITY_TYPE</span></code> can also
+ be used to overcome this issue:
+ </p>
+<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span>
+ <span class="special">...</span>
+ <span class="identifier">BOOST_IDENTITY_TYPE</span><span class="special">((::</span><span class="identifier">sign_t</span><span class="special">))</span> <span class="identifier">sign</span><span class="special">,</span> <span class="comment">// OK.</span>
+ <span class="special">...</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="special">...</span>
+<span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">f</span><span class="special">)</span>
+</pre>
+<div class="note"><table border="0" summary="Note">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../doc/src/images/note.png"></td>
+<th align="left">Note</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ Often, there might be better ways to overcome this limitation that lead
+ to code which is more readable than the one using the <code class="computeroutput"><span class="identifier">BOOST_IDENTITY_TYPE</span></code>
+ macro. For example, in this case the symbols <code class="computeroutput"><span class="special">::</span></code>
+ could have been simply dropped to obtain the following valid and perhaps
+ more readable code:
+ </p></td></tr>
+</table></div>
+<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span>
+ <span class="special">...</span>
+ <span class="identifier">sign_t</span> <span class="identifier">sign</span><span class="special">,</span> <span class="comment">// OK.</span>
+ <span class="special">...</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="special">...</span>
+<span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">f</span><span class="special">)</span>
+</pre>
+<p>
+ <span class="bold"><strong>(3)</strong></span> The default parameter value <code class="computeroutput"><span class="identifier">key_size</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <span class="identifier">size_t</span><span class="special">&gt;::</span><span class="identifier">value</span></code>
+ contains a comma <code class="computeroutput"><span class="special">,</span></code> after the
+ first template parameter <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span></code>.
+ Again, this comma is not wrapped by any parenthesis <code class="computeroutput"><span class="special">()</span></code>
+ so it will cause a preprocessor error. Because this is a value expression
+ (and not a type expression), it can be simply wrapped within an extra set
+ of round parenthesis <code class="computeroutput"><span class="special">()</span></code>:
+ </p>
+<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span>
+ <span class="special">...</span>
+ <span class="keyword">const</span> <span class="identifier">size_t</span><span class="special">&amp;</span> <span class="identifier">factor</span><span class="special">,</span> <span class="keyword">default</span>
+ <span class="special">(</span><span class="identifier">key_size</span><span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">,</span> <span class="identifier">size_t</span><span class="special">&gt;::</span><span class="identifier">value</span><span class="special">),</span> <span class="comment">// OK.</span>
+ <span class="special">...</span>
+<span class="special">)</span> <span class="special">{</span>
+ <span class="special">...</span>
+<span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">f</span><span class="special">)</span>
+</pre>
+<p>
+ <span class="bold"><strong>(4)</strong></span> The default parameter value <code class="computeroutput"><span class="identifier">cat</span><span class="special">(</span><span class="string">":"</span><span class="special">,</span> <span class="string">" "</span><span class="special">)</span></code> is instead fine because it contains a comma
+ <code class="computeroutput"><span class="special">,</span></code> which is already wrapped by
+ the parenthesis <code class="computeroutput"><span class="special">()</span></code> of the function
+ call <code class="computeroutput"><span class="identifier">cat</span><span class="special">(...)</span></code>.
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Advanced_Topics.assigning_and_returning"></a><a class="link" href="Advanced_Topics.html#boost_localfunction.Advanced_Topics.assigning_and_returning" title="Assigning and Returning">Assigning
+ and Returning</a>
+</h3></div></div></div>
+<p>
+ Local functions are function objects so it is possible to assign them to
+ other functors like Boost.Function
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span></code> in order to store the local function
+ into a variable, pass it as a parameter to another function, or return it
+ from the enclosing function.
+ </p>
+<p>
+ For example (see also "return_assign.cpp"):
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">call1</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span><span class="special">&lt;</span><span class="keyword">int</span> <span class="special">(</span><span class="keyword">int</span><span class="special">)&gt;</span> <span class="identifier">f</span><span class="special">)</span> <span class="special">{</span> <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">f</span><span class="special">(</span><span class="number">1</span><span class="special">)</span> <span class="special">==</span> <span class="number">5</span> <span class="special">);</span> <span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">call0</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span><span class="special">&lt;</span><span class="keyword">int</span> <span class="special">(</span><span class="keyword">void</span><span class="special">)&gt;</span> <span class="identifier">f</span><span class="special">)</span> <span class="special">{</span> <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">f</span><span class="special">()</span> <span class="special">==</span> <span class="number">5</span> <span class="special">);</span> <span class="special">}</span>
+
+<span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span><span class="special">&lt;</span><span class="keyword">int</span> <span class="special">(</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">int</span><span class="special">)&gt;</span> <span class="identifier">linear</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">slope</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span><span class="special">&lt;</span> <span class="keyword">int</span> <span class="special">(</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">int</span><span class="special">)</span> <span class="special">&gt;</span> <span class="identifier">l2</span><span class="special">;</span>
+
+ <span class="keyword">int</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="identifier">bind</span> <span class="identifier">slope</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">default</span> <span class="number">1</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">y</span><span class="special">,</span> <span class="keyword">default</span> <span class="number">2</span><span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">x</span> <span class="special">+</span> <span class="identifier">slope</span> <span class="special">*</span> <span class="identifier">y</span><span class="special">;</span>
+ <span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">lin</span><span class="special">)</span>
+
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span><span class="special">&lt;</span><span class="keyword">int</span> <span class="special">(</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">int</span><span class="special">)&gt;</span> <span class="identifier">f</span> <span class="special">=</span> <span class="identifier">lin</span><span class="special">;</span> <span class="comment">// Assign to local variable.</span>
+ <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">f</span><span class="special">(</span><span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">)</span> <span class="special">==</span> <span class="number">5</span> <span class="special">);</span>
+
+ <span class="identifier">call1</span><span class="special">(</span><span class="identifier">lin</span><span class="special">);</span> <span class="comment">// Pass to other functions.</span>
+ <span class="identifier">call0</span><span class="special">(</span><span class="identifier">lin</span><span class="special">);</span>
+
+ <span class="keyword">return</span> <span class="identifier">lin</span><span class="special">;</span> <span class="comment">// Return.</span>
+<span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">call</span><span class="special">(</span><span class="keyword">void</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span><span class="special">&lt;</span><span class="keyword">int</span> <span class="special">(</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">int</span><span class="special">)&gt;</span> <span class="identifier">f</span> <span class="special">=</span> <span class="identifier">linear</span><span class="special">(</span><span class="number">2</span><span class="special">);</span>
+ <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">f</span><span class="special">(</span><span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">)</span> <span class="special">==</span> <span class="number">5</span> <span class="special">);</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+<p>
+ Note that:
+ </p>
+<div class="important"><table border="0" summary="Important">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../../doc/src/images/important.png"></td>
+<th align="left">Important</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ As with <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ lambda</a> functions, programmers are responsible to ensure that bound
+ references are valid in any scope where the local function object is called.
+ </p></td></tr>
+</table></div>
+<p>
+ This might be tricky to verify in a program so in general it is better to
+ never bind by reference when a local function is returned by the enclosing
+ scope to a different scope (see a few examples on this topic in the <a class="link" href="../">Examples</a> section).
+ </p>
+<p>
+ In addition, a local function can bind and call another local function. Local
+ functions should always be bound by constant reference <code class="computeroutput"><span class="keyword">const</span>
+ <span class="identifier">bind</span><span class="special">&amp;</span></code>
+ to avoid unnecessary copies. For example, the following local function <code class="computeroutput"><span class="identifier">inc_sum</span></code> binds the local function <code class="computeroutput"><span class="identifier">inc</span></code> so <code class="computeroutput"><span class="identifier">inc_sum</span></code>
+ can call <code class="computeroutput"><span class="identifier">inc</span></code> (see aslo "transform.cpp"):
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">offset</span> <span class="special">=</span> <span class="number">5</span><span class="special">;</span>
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">v</span><span class="special">;</span>
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">w</span><span class="special">;</span>
+
+<span class="keyword">for</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span> <span class="identifier">i</span> <span class="special">&lt;=</span> <span class="number">2</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> <span class="identifier">v</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">i</span> <span class="special">*</span> <span class="number">10</span><span class="special">);</span>
+<span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">v</span><span class="special">[</span><span class="number">0</span><span class="special">]</span> <span class="special">==</span> <span class="number">10</span> <span class="special">);</span> <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">v</span><span class="special">[</span><span class="number">1</span><span class="special">]</span> <span class="special">==</span> <span class="number">20</span> <span class="special">);</span>
+<span class="identifier">w</span><span class="special">.</span><span class="identifier">resize</span><span class="special">(</span><span class="identifier">v</span><span class="special">.</span><span class="identifier">size</span><span class="special">());</span>
+
+<span class="keyword">int</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">bind</span><span class="special">&amp;</span> <span class="identifier">offset</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">i</span><span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="special">++</span><span class="identifier">i</span> <span class="special">+</span> <span class="identifier">offset</span><span class="special">;</span>
+<span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">inc</span><span class="special">)</span>
+
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">transform</span><span class="special">(</span><span class="identifier">v</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">v</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span> <span class="identifier">w</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">inc</span><span class="special">);</span>
+<span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">w</span><span class="special">[</span><span class="number">0</span><span class="special">]</span> <span class="special">==</span> <span class="number">16</span> <span class="special">);</span> <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">w</span><span class="special">[</span><span class="number">1</span><span class="special">]</span> <span class="special">==</span> <span class="number">26</span> <span class="special">);</span>
+
+<span class="keyword">int</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">bind</span><span class="special">&amp;</span> <span class="identifier">inc</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">i</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">j</span><span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">inc</span><span class="special">(</span><span class="identifier">i</span> <span class="special">+</span> <span class="identifier">j</span><span class="special">);</span> <span class="comment">// Call the other bound local function.</span>
+<span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">inc_sum</span><span class="special">)</span>
+
+<span class="identifier">offset</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">transform</span><span class="special">(</span><span class="identifier">v</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">v</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span> <span class="identifier">w</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">v</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">inc_sum</span><span class="special">);</span>
+<span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">v</span><span class="special">[</span><span class="number">0</span><span class="special">]</span> <span class="special">==</span> <span class="number">27</span> <span class="special">);</span> <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">v</span><span class="special">[</span><span class="number">1</span><span class="special">]</span> <span class="special">==</span> <span class="number">47</span> <span class="special">);</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Advanced_Topics.nesting"></a><a class="link" href="Advanced_Topics.html#boost_localfunction.Advanced_Topics.nesting" title="Nesting">Nesting</a>
+</h3></div></div></div>
+<p>
+ It is possible to nest local functions into one another. For example (see
+ also "nesting.cpp"):
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">x</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+
+<span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="identifier">bind</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION_PARAMS</span><span class="special">(</span><span class="identifier">bind</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">{</span> <span class="comment">// Nested.</span>
+ <span class="identifier">x</span><span class="special">++;</span>
+ <span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">g</span><span class="special">)</span>
+
+ <span class="identifier">x</span><span class="special">--;</span>
+ <span class="identifier">g</span><span class="special">();</span> <span class="comment">// Nested local function call.</span>
+<span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">f</span><span class="special">)</span>
+
+<span class="identifier">f</span><span class="special">();</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Advanced_Topics.deducing_bound_types__concepts__etc_"></a><a class="link" href="Advanced_Topics.html#boost_localfunction.Advanced_Topics.deducing_bound_types__concepts__etc_" title="Deducing Bound Types (concepts, etc)">Deducing
+ Bound Types (concepts, etc)</a>
+</h3></div></div></div>
+<p>
+ This library never requires to explicitly specify the type of the bound variables.
+ From within local functions, programmers can access the type of a bound variable
+ using the following macro:
+ </p>
+<pre class="programlisting"><span class="identifier">BOOST_LOCAL_FUNCTION_TYPEOF</span><span class="special">(</span><span class="emphasis"><em>bound-variable-name</em></span><span class="special">)</span>
+</pre>
+<p>
+ The <code class="computeroutput">BOOST_LOCAL_FUNCTION_TYPEOF</code>
+ macro expands to a type expression that evaluates (at compile-time) to the
+ fully qualified type of the bound variable with the specified name.
+ </p>
+<div class="note"><table border="0" summary="Note">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../doc/src/images/note.png"></td>
+<th align="left">Note</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ This type expression is fully qualified in the sense that it will be constant
+ if the variable is bound by constant <code class="computeroutput"><span class="keyword">const</span>
+ <span class="identifier">bind</span><span class="special">[&amp;]</span></code>
+ and it will also be a reference is the variable is bound by reference
+ <code class="computeroutput"><span class="special">[</span><span class="keyword">const</span><span class="special">]</span> <span class="identifier">bind</span><span class="special">&amp;</span></code> (if needed, programmers can strip
+ away the <code class="computeroutput"><span class="keyword">const</span></code> and <code class="computeroutput"><span class="special">&amp;</span></code> qualifiers using <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">remove_const</span></code>
+ and <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">remove_reference</span></code>, see Boost.TypeTraits).
+ </p></td></tr>
+</table></div>
+<p>
+ The deduced bound type can be used within the body to declare a local variable,
+ to check concepts, etc. For example (see also "typeof.cpp" and "addable.hpp"):
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">sum</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">factor</span> <span class="special">=</span> <span class="number">10</span><span class="special">;</span>
+
+<span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">bind</span> <span class="identifier">factor</span><span class="special">,</span> <span class="identifier">bind</span><span class="special">&amp;</span> <span class="identifier">sum</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">num</span><span class="special">)</span> <span class="special">{</span>
+ <span class="comment">// Typeof for concept checking.</span>
+ <span class="identifier">BOOST_CONCEPT_ASSERT</span><span class="special">((</span><span class="identifier">Addable</span><span class="special">&lt;</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">remove_reference</span><span class="special">&lt;</span>
+ <span class="identifier">BOOST_LOCAL_FUNCTION_TYPEOF</span><span class="special">(</span><span class="identifier">sum</span><span class="special">)&gt;::</span><span class="identifier">type</span><span class="special">&gt;));</span>
+ <span class="comment">// Typeof for declarations.</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">remove_reference</span><span class="special">&lt;</span><span class="identifier">BOOST_LOCAL_FUNCTION_TYPEOF</span><span class="special">(</span>
+ <span class="identifier">factor</span><span class="special">)&gt;::</span><span class="identifier">type</span> <span class="identifier">mult</span> <span class="special">=</span> <span class="identifier">factor</span> <span class="special">*</span> <span class="identifier">num</span><span class="special">;</span>
+ <span class="identifier">sum</span> <span class="special">+=</span> <span class="identifier">mult</span><span class="special">;</span>
+<span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">add</span><span class="special">)</span>
+
+<span class="identifier">add</span><span class="special">(</span><span class="number">6</span><span class="special">);</span>
+</pre>
+<p>
+ </p>
+<p>
+ Within templates, <code class="computeroutput">BOOST_LOCAL_FUNCTION_TYPEOF</code>
+ does not require to be prefixed by the <code class="computeroutput"><span class="keyword">typename</span></code>
+ keyword but eventual type manipulations need the <code class="computeroutput"><span class="keyword">typename</span></code>
+ prefix as usual (see also "typeof_template.cpp" and
+ "addable.hpp"):
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
+<span class="identifier">T</span> <span class="identifier">calculate</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">factor</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">T</span> <span class="identifier">sum</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+
+ <span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION_TPL</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">bind</span> <span class="identifier">factor</span><span class="special">,</span> <span class="identifier">bind</span><span class="special">&amp;</span> <span class="identifier">sum</span><span class="special">,</span> <span class="identifier">T</span> <span class="identifier">num</span><span class="special">)</span> <span class="special">{</span>
+ <span class="comment">// Typeof for concept checking.</span>
+ <span class="identifier">BOOST_CONCEPT_ASSERT</span><span class="special">((</span><span class="identifier">Addable</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">remove_reference</span><span class="special">&lt;</span>
+ <span class="identifier">BOOST_LOCAL_FUNCTION_TYPEOF</span><span class="special">(</span><span class="identifier">sum</span><span class="special">)&gt;::</span><span class="identifier">type</span><span class="special">&gt;));</span>
+ <span class="comment">// Typeof for declarations.</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">remove_reference</span><span class="special">&lt;</span><span class="identifier">BOOST_LOCAL_FUNCTION_TYPEOF</span><span class="special">(</span>
+ <span class="identifier">factor</span><span class="special">)&gt;::</span><span class="identifier">type</span> <span class="identifier">mult</span> <span class="special">=</span> <span class="identifier">factor</span> <span class="special">*</span> <span class="identifier">num</span><span class="special">;</span>
+ <span class="identifier">sum</span> <span class="special">+=</span> <span class="identifier">mult</span><span class="special">;</span>
+ <span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">add</span><span class="special">)</span>
+
+ <span class="identifier">add</span><span class="special">(</span><span class="number">6</span><span class="special">);</span>
+ <span class="keyword">return</span> <span class="identifier">sum</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Advanced_Topics.specifying_types"></a><a class="link" href="Advanced_Topics.html#boost_localfunction.Advanced_Topics.specifying_types" title="Specifying Types">Specifying
+ Types</a>
+</h3></div></div></div>
+<p>
+ While not required, it is possible to explicitly specify the type of a bound
+ variable so the library will not internally use Boost.Typeof
+ to automatically deduce the type. When specified, the bound variable type
+ must follow the <code class="computeroutput"><span class="identifier">bind</span></code> "keyword"
+ and it must be wrapped within round parenthesis <code class="computeroutput"><span class="special">()</span></code>:
+ </p>
+<pre class="programlisting"><span class="identifier">bind</span><span class="special">(</span><span class="emphasis"><em>variable-type</em></span><span class="special">)</span> <span class="emphasis"><em>variable-name</em></span> <span class="comment">// Bind by value with explicit type.</span>
+<span class="identifier">bind</span><span class="special">(</span><span class="emphasis"><em>variable-type</em></span><span class="special">)&amp;</span> <span class="emphasis"><em>variable-name</em></span> <span class="comment">// Bind by reference with explicit type.</span>
+<span class="keyword">const</span> <span class="identifier">bind</span><span class="special">(</span><span class="emphasis"><em>variable-type</em></span><span class="special">)</span> <span class="emphasis"><em>variable-name</em></span> <span class="comment">// Bind by constant value with explicit type.</span>
+<span class="keyword">const</span> <span class="identifier">bind</span><span class="special">(</span><span class="emphasis"><em>variable-type</em></span><span class="special">)&amp;</span> <span class="emphasis"><em>variable-name</em></span> <span class="comment">// Bind by constant reference with explicit type.</span>
+<span class="identifier">bind</span><span class="special">(</span><span class="emphasis"><em>class-type</em></span><span class="special">*)</span> <span class="identifier">this_</span> <span class="comment">// Bind object `this` with type.</span>
+<span class="keyword">const</span> <span class="identifier">bind</span><span class="special">(</span><span class="emphasis"><em>class-type</em></span><span class="special">*)</span> <span class="identifier">this_</span> <span class="comment">// Bind object `this` by constant with type.</span>
+</pre>
+<p>
+ Note that within the local function body it is always possible to abstract
+ the access to the type of a bound variable using <code class="computeroutput">BOOST_LOCAL_FUNCTION_TYPEOF</code>
+ (even when the bound variable type is explicitly specified).
+ </p>
+<p>
+ The library also needs to use Boost.Typeof
+ to determine the local function result type because this type specified outside
+ the <code class="computeroutput">BOOST_LOCAL_FUNCTION</code>
+ macro. Thus it is also possible to specify the local function result type
+ as one of the <code class="computeroutput">BOOST_LOCAL_FUNCTION</code>
+ macro parameters prefixed by <code class="computeroutput"><span class="keyword">return</span></code>
+ so the library will not use Boost.Typeof
+ to deduce it:
+ </p>
+<pre class="programlisting"><span class="identifier">BOOST_LOCAL_FUNCTION_TYPE</span><span class="special">(</span><span class="keyword">return</span> <code class="literal"><span class="emphasis"><em>result-type</em></span></code><span class="special">,</span> <span class="special">...)</span>
+</pre>
+<p>
+ The following example specifies the type of all bound variables and of the
+ local function result (see also "add_typed.cpp"): <sup>[<a name="boost_localfunction.Advanced_Topics.specifying_types.f0" href="#ftn.boost_localfunction.Advanced_Topics.specifying_types.f0" class="footnote">19</a>]</sup>
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">adder</span> <span class="special">{</span>
+ <span class="identifier">adder</span><span class="special">():</span> <span class="identifier">sum_</span><span class="special">(</span><span class="number">0</span><span class="special">)</span> <span class="special">{}</span>
+
+ <span class="keyword">int</span> <span class="identifier">sum</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;&amp;</span> <span class="identifier">nums</span><span class="special">,</span> <span class="keyword">const</span> <span class="keyword">int</span><span class="special">&amp;</span> <span class="identifier">factor</span> <span class="special">=</span> <span class="number">10</span><span class="special">)</span> <span class="special">{</span>
+ <span class="comment">// Explicitly specify bound variable and result types.</span>
+ <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">bind</span><span class="special">(</span><span class="keyword">const</span> <span class="keyword">int</span><span class="special">&amp;)</span> <span class="identifier">factor</span><span class="special">,</span>
+ <span class="identifier">bind</span><span class="special">(</span><span class="identifier">adder</span><span class="special">*)</span> <span class="identifier">this_</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">num</span><span class="special">,</span> <span class="keyword">return</span> <span class="keyword">int</span><span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">this_</span><span class="special">-&gt;</span><span class="identifier">sum_</span> <span class="special">+=</span> <span class="identifier">factor</span> <span class="special">*</span> <span class="identifier">num</span><span class="special">;</span>
+ <span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">add</span><span class="special">)</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">nums</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">nums</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span> <span class="identifier">add</span><span class="special">);</span>
+ <span class="keyword">return</span> <span class="identifier">sum_</span><span class="special">;</span>
+ <span class="special">}</span>
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="keyword">int</span> <span class="identifier">sum_</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ </p>
+<p>
+ Unless necessary, it is recommended to not specify the bound variable and
+ result types. Let the library deduce these types so the local function syntax
+ is more concise and the local function declaration will not have to change
+ if a bound variable type changes (facilitating maintenance).
+ </p>
+<div class="note"><table border="0" summary="Note">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../doc/src/images/note.png"></td>
+<th align="left">Note</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ Even when the result type and all bound variable types are explicitly specified,
+ the library implementation still internally uses Boost.Typeof
+ to deduce the local function object type (see the <a class="link" href="../">Implementation</a>
+ section). However, this type is automatically registered with Boost.Typeof
+ by this library so programmers will never be required to perform explicit
+ Boost.Typeof
+ registrations when they specify all result and bound variable types.
+ </p></td></tr>
+</table></div>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Advanced_Topics.inlining"></a><a class="link" href="Advanced_Topics.html#boost_localfunction.Advanced_Topics.inlining" title="Inlining">Inlining</a>
+</h3></div></div></div>
+<p>
+ Local functions can be declared inline to increase the chances that the compiler
+ will be able to reduce the run-time of the local function call by inlining
+ the generated assembly code. A local function is declared inline by prefixing
+ the local function name passed to the <code class="computeroutput">BOOST_LOCAL_FUNCTION_NAME</code>
+ macro with the "keyword" <code class="computeroutput"><span class="keyword">inline</span></code>:
+ </p>
+<pre class="programlisting"><span class="emphasis"><em>result-type</em></span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="emphasis"><em>parameters</em></span><span class="special">)</span> <span class="special">{</span>
+ <span class="special">...</span> <span class="comment">// Body.</span>
+<span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="keyword">inline</span> <span class="emphasis"><em>name</em></span><span class="special">)</span> <span class="comment">// Inlining.</span>
+</pre>
+<p>
+ When inlining a local function, note the following:
+ </p>
+<div class="itemizedlist"><ul class="itemizedlist" type="disc">
+<li class="listitem">
+ On C++03
+ compliant compilers, inlined local functions always have a run-time comparable
+ to their equivalent implementation that uses local functors (see the
+ <a class="link" href="../">Alternatives</a> section).
+ However, inlined local functions have the important limitation that they
+ cannot be assigned to other functors (like <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span></code>)
+ and they cannot be passed as template parameters. <sup>[<a name="boost_localfunction.Advanced_Topics.inlining.f0" href="#ftn.boost_localfunction.Advanced_Topics.inlining.f0" class="footnote">20</a>]</sup>
+ </li>
+<li class="listitem">
+ On C++11
+ compilers, <code class="computeroutput"><span class="keyword">inline</span></code> has no
+ effect because this library will automatically generate code that uses
+ C++11 specific
+ features to inline the local function calls whenever possible even if
+ the local function is not declared inline. Furthermore, non C++11
+ local functions can always be passes as template parameters even when
+ they are declared inline.
+ </li>
+</ul></div>
+<div class="important"><table border="0" summary="Important">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../../doc/src/images/important.png"></td>
+<th align="left">Important</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ It is recommended to not declare a local function inlined unless it is
+ strictly necessary for optimizing pure C++03
+ compliant code (because in all other cases this library will automatically
+ take advantage of C++11
+ features to optimize the local function calls while always allowing to
+ pass the local function as a template parameter).
+ </p></td></tr>
+</table></div>
+<p>
+ For example, the following local function is declared inlined (thus a for-loop
+ needs to be used for portability instead of passing the local function as
+ a template parameter to the <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span></code>
+ algorithm, see also "add_inline.cpp"):
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">sum</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">factor</span> <span class="special">=</span> <span class="number">10</span><span class="special">;</span>
+
+<span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">bind</span> <span class="identifier">factor</span><span class="special">,</span> <span class="identifier">bind</span><span class="special">&amp;</span> <span class="identifier">sum</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">num</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">sum</span> <span class="special">+=</span> <span class="identifier">factor</span> <span class="special">*</span> <span class="identifier">num</span><span class="special">;</span>
+<span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="keyword">inline</span> <span class="identifier">add</span><span class="special">)</span> <span class="comment">// Inlined.</span>
+
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">v</span><span class="special">(</span><span class="number">100</span><span class="special">);</span>
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">fill</span><span class="special">(</span><span class="identifier">v</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">v</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span> <span class="number">1</span><span class="special">);</span>
+
+<span class="keyword">for</span><span class="special">(</span><span class="identifier">size_t</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special">&lt;</span> <span class="identifier">v</span><span class="special">.</span><span class="identifier">size</span><span class="special">();</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> <span class="identifier">add</span><span class="special">(</span><span class="identifier">v</span><span class="special">[</span><span class="identifier">i</span><span class="special">]);</span> <span class="comment">// Cannot use for_each.</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Advanced_Topics.recursion"></a><a class="link" href="Advanced_Topics.html#boost_localfunction.Advanced_Topics.recursion" title="Recursion">Recursion</a>
+</h3></div></div></div>
+<p>
+ Local functions can be declared recursive
+ so a local function can recursively call itself from its body (as usual with
+ C++ functions). A local function is declared recursive by prefixing the local
+ function name passed to <code class="computeroutput">BOOST_LOCAL_FUNCTION_NAME</code>
+ macro with the "keyword" <code class="computeroutput"><span class="identifier">recursive</span></code>:
+ </p>
+<pre class="programlisting"><span class="emphasis"><em>result-type</em></span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="emphasis"><em>parameters</em></span><span class="special">)</span> <span class="special">{</span>
+ <span class="special">...</span> <span class="comment">// Body.</span>
+<span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">recursive</span> <span class="emphasis"><em>name</em></span><span class="special">)</span> <span class="comment">// Recursive.</span>
+</pre>
+<p>
+ For example, the following local function is used to recursively calculate
+ the factorials of all the numbers in the specified vector (see also "factorial.cpp"):
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">calculator</span> <span class="special">{</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">results</span><span class="special">;</span>
+
+ <span class="keyword">void</span> <span class="identifier">factorials</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;&amp;</span> <span class="identifier">nums</span><span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">int</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="identifier">bind</span> <span class="identifier">this_</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">num</span><span class="special">,</span>
+ <span class="keyword">bool</span> <span class="identifier">recursion</span><span class="special">,</span> <span class="keyword">default</span> <span class="keyword">false</span><span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">int</span> <span class="identifier">result</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+
+ <span class="keyword">if</span> <span class="special">(</span><span class="identifier">n</span> <span class="special">&lt;</span> <span class="number">2</span> <span class="special">)</span> <span class="identifier">result</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span>
+ <span class="keyword">else</span> <span class="identifier">result</span> <span class="special">=</span> <span class="identifier">n</span> <span class="special">*</span> <span class="identifier">factorial</span><span class="special">(</span><span class="identifier">n</span> <span class="special">-</span> <span class="number">1</span><span class="special">,</span> <span class="keyword">true</span><span class="special">);</span> <span class="comment">// Recursive call.</span>
+
+ <span class="keyword">if</span> <span class="special">(!</span><span class="identifier">recursion</span><span class="special">)</span> <span class="identifier">this_</span><span class="special">-&gt;</span><span class="identifier">results</span><span class="special">.</span><span class="identifier">push_back</span><span class="special">(</span><span class="identifier">result</span><span class="special">);</span>
+ <span class="keyword">return</span> <span class="identifier">result</span><span class="special">;</span>
+ <span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">recursive</span> <span class="identifier">factorial</span><span class="special">)</span> <span class="comment">// Recursive.</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">nums</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">nums</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span> <span class="identifier">factorial</span><span class="special">);</span>
+ <span class="special">}</span>
+<span class="special">};</span>
+</pre>
+<p>
+ </p>
+<p>
+ Compilers have not been observed to be able to inline recursive local function
+ calls (not even when the recursive local function is also declared inline).
+ </p>
+<div class="warning"><table border="0" summary="Warning">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../doc/src/images/warning.png"></td>
+<th align="left">Warning</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ Recursive local functions should never be assigned to another functor object
+ or called outside their declaration scope. Therefore, if a local function
+ is assigned to <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span></code>, returned from the enclosing
+ function, and called in a different scope, the result in undefined behaviour
+ (which will likely generate a run-time error). <sup>[<a name="boost_localfunction.Advanced_Topics.recursion.f0" href="#ftn.boost_localfunction.Advanced_Topics.recursion.f0" class="footnote">21</a>]</sup> This is not a limitation with respect to <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ lambda</a> functions because lambdas can never call themselves recursively
+ (in other words, there is no recursive lambda function that can successfully
+ be called outside its declaration scope because there is no recursive lambda
+ function period).
+ </p></td></tr>
+</table></div>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Advanced_Topics.overloading"></a><a class="link" href="Advanced_Topics.html#boost_localfunction.Advanced_Topics.overloading" title="Overloading">Overloading</a>
+</h3></div></div></div>
+<p>
+ It is possible to overload local functions using __Boost_FunctionalOverloadedFunction__
+ <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">overloaded_function</span></code> from the header <code class="computeroutput"><span class="string">"boost/functional/overloaded_function.hpp"</span></code>
+ (see the __Boost_FunctionalOverloadedFunction__ documentation for more detail).
+ </p>
+<p>
+ In the following example, the overloaded function object <code class="computeroutput"><span class="identifier">add</span></code>
+ can be called with signatures from either the local function <code class="computeroutput"><span class="identifier">add_s</span></code>, or the local function <code class="computeroutput"><span class="identifier">add_d</span></code>, or the local function <code class="computeroutput"><span class="identifier">add_d</span></code> with its extra default parameter,
+ or the function pointer <code class="computeroutput"><span class="identifier">add_i</span></code>
+ (see also "overload.cpp"):
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">add_i</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">x</span> <span class="special">+</span> <span class="identifier">y</span><span class="special">;</span> <span class="special">}</span>
+
+<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span> <span class="identifier">test_overload</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">s</span> <span class="special">=</span> <span class="string">"abc"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span>
+ <span class="keyword">const</span> <span class="identifier">bind</span><span class="special">&amp;</span> <span class="identifier">s</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">s</span> <span class="special">+</span> <span class="identifier">x</span><span class="special">;</span>
+ <span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">add_s</span><span class="special">)</span>
+
+ <span class="keyword">double</span> <span class="identifier">d</span> <span class="special">=</span> <span class="number">1.23</span><span class="special">;</span>
+ <span class="keyword">double</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">bind</span> <span class="identifier">d</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">double</span> <span class="identifier">y</span><span class="special">,</span> <span class="keyword">default</span> <span class="number">0</span><span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">d</span> <span class="special">+</span> <span class="identifier">x</span> <span class="special">+</span> <span class="identifier">y</span><span class="special">;</span>
+ <span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">add_d</span><span class="special">)</span>
+
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">overloaded_function</span><span class="special">&lt;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&amp;)</span>
+ <span class="special">,</span> <span class="keyword">double</span> <span class="special">(</span><span class="keyword">double</span><span class="special">)</span>
+ <span class="special">,</span> <span class="keyword">double</span> <span class="special">(</span><span class="keyword">double</span><span class="special">,</span> <span class="keyword">double</span><span class="special">)</span> <span class="comment">// Overload giving default param.</span>
+ <span class="special">,</span> <span class="keyword">int</span> <span class="special">(</span><span class="keyword">int</span><span class="special">,</span> <span class="keyword">int</span><span class="special">)</span>
+ <span class="special">&gt;</span> <span class="identifier">add</span><span class="special">(</span><span class="identifier">add_s</span><span class="special">,</span> <span class="identifier">add_d</span><span class="special">,</span> <span class="identifier">add_d</span><span class="special">,</span> <span class="identifier">add_i</span><span class="special">);</span> <span class="comment">// Overloaded function object.</span>
+
+ <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">add</span><span class="special">(</span><span class="string">"xyz"</span><span class="special">)</span> <span class="special">==</span> <span class="string">"abcxyz"</span> <span class="special">);</span> <span class="comment">// Call `add_s`.</span>
+ <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">fabs</span><span class="special">(</span><span class="identifier">add</span><span class="special">(</span><span class="number">3.21</span><span class="special">)</span> <span class="special">-</span> <span class="number">4.44</span><span class="special">)</span> <span class="special">&lt;</span> <span class="number">0.001</span> <span class="special">);</span> <span class="comment">// Call `add_d` (no default).</span>
+ <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">fabs</span><span class="special">(</span><span class="identifier">add</span><span class="special">(</span><span class="number">3.21</span><span class="special">,</span> <span class="number">40.0</span><span class="special">)</span> <span class="special">-</span> <span class="number">44.44</span><span class="special">)</span> <span class="special">&lt;</span> <span class="number">0.001</span><span class="special">);</span> <span class="comment">// Call `add_d`.</span>
+ <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">add</span><span class="special">(</span><span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">)</span> <span class="special">==</span> <span class="number">3</span> <span class="special">);</span> <span class="comment">// Call `add_i`.</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Advanced_Topics.exception_specifications"></a><a class="link" href="Advanced_Topics.html#boost_localfunction.Advanced_Topics.exception_specifications" title="Exception Specifications">Exception
+ Specifications</a>
+</h3></div></div></div>
+<p>
+ It is possible to program exception specifications for local functions by
+ specifying them after the <code class="computeroutput">BOOST_LOCAL_FUNCTION</code>
+ macro and before the body code block <code class="computeroutput"><span class="special">{</span>
+ <span class="special">...</span> <span class="special">}</span></code>.
+ </p>
+<div class="important"><table border="0" summary="Important">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../../doc/src/images/important.png"></td>
+<th align="left">Important</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ Note that the exception specifications only apply to the body code specified
+ by programmers and they do not apply to the rest of the code automatically
+ generated by the macro expansions to implement local functions. For example,
+ even if the body code is specified to throw no exception using <code class="computeroutput"><span class="keyword">throw</span> <span class="special">()</span> <span class="special">{</span> <span class="special">...</span> <span class="special">}</span></code>,
+ the execution of the library code automatically generated by the macros
+ could still throw (if there is no memory, etc).
+ </p></td></tr>
+</table></div>
+<p>
+ For example (see also "add_except.cpp"):
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="keyword">double</span> <span class="identifier">sum</span> <span class="special">=</span> <span class="number">0.0</span><span class="special">;</span>
+<span class="keyword">int</span> <span class="identifier">factor</span> <span class="special">=</span> <span class="number">10</span><span class="special">;</span>
+
+<span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">bind</span> <span class="identifier">factor</span><span class="special">,</span> <span class="identifier">bind</span><span class="special">&amp;</span> <span class="identifier">sum</span><span class="special">,</span>
+ <span class="keyword">double</span> <span class="identifier">num</span><span class="special">)</span> <span class="keyword">throw</span><span class="special">()</span> <span class="special">{</span> <span class="comment">// Throw nothing.</span>
+ <span class="identifier">sum</span> <span class="special">+=</span> <span class="identifier">factor</span> <span class="special">*</span> <span class="identifier">num</span><span class="special">;</span>
+<span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">add</span><span class="special">)</span>
+
+<span class="identifier">add</span><span class="special">(</span><span class="number">100</span><span class="special">);</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Advanced_Topics.storage_classifiers___auto__and__register__"></a><a class="link" href="Advanced_Topics.html#boost_localfunction.Advanced_Topics.storage_classifiers___auto__and__register__" title="Storage Classifiers (auto and register)">Storage
+ Classifiers (<code class="computeroutput"><span class="keyword">auto</span></code> and <code class="computeroutput"><span class="keyword">register</span></code>)</a>
+</h3></div></div></div>
+<p>
+ Local function parameters support the storage classifiers as usual in C++03.
+ The <code class="computeroutput"><span class="keyword">auto</span></code> storage classifier
+ is specified as: <sup>[<a name="boost_localfunction.Advanced_Topics.storage_classifiers___auto__and__register__.f0" href="#ftn.boost_localfunction.Advanced_Topics.storage_classifiers___auto__and__register__.f0" class="footnote">22</a>]</sup>
+ </p>
+<pre class="programlisting"><span class="keyword">auto</span> <span class="emphasis"><em>parameter-type parameter-name</em></span>
+</pre>
+<p>
+ The <code class="computeroutput"><span class="keyword">register</span></code> storage classifier
+ is specified as:
+ </p>
+<pre class="programlisting"><span class="keyword">register</span> <span class="emphasis"><em>parameter-type parameter-name</em></span>
+</pre>
+<p>
+ For example (see also "add_classifiers.cpp"):
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">auto</span> <span class="keyword">int</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">register</span> <span class="keyword">int</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span> <span class="comment">// Classifers.</span>
+ <span class="keyword">return</span> <span class="identifier">x</span> <span class="special">+</span> <span class="identifier">y</span><span class="special">;</span>
+<span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">add</span><span class="special">)</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Advanced_Topics.limitations__operators__etc_"></a><a class="link" href="Advanced_Topics.html#boost_localfunction.Advanced_Topics.limitations__operators__etc_" title="Limitations (operators, etc)">Limitations
+ (operators, etc)</a>
+</h3></div></div></div>
+<p>
+ The following table summarizes all C++ function features indicating those
+ features that are not supported by this library for local functions.
+ </p>
+<div class="informaltable"><table class="table">
+<colgroup>
+<col>
+<col>
+<col>
+</colgroup>
+<thead><tr>
+<th>
+ <p>
+ C++ Function Feature
+ </p>
+ </th>
+<th>
+ <p>
+ Local Function Support
+ </p>
+ </th>
+<th>
+ <p>
+ Reason
+ </p>
+ </th>
+</tr></thead>
+<tbody>
+<tr>
+<td>
+ <p>
+ <code class="computeroutput"><span class="keyword">export</span></code>
+ </p>
+ </td>
+<td>
+ <p>
+ No
+ </p>
+ </td>
+<td>
+ <p>
+ This is not supported because local functions cannot be templates
+ (plus most C++ compilers do not implement <code class="computeroutput"><span class="keyword">export</span></code>).
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <code class="computeroutput"><span class="keyword">template</span><span class="special">&lt;</span></code><span class="emphasis"><em>template-parameter-list</em></span><code class="computeroutput"><span class="special">&gt;</span></code>
+ </p>
+ </td>
+<td>
+ <p>
+ No
+ </p>
+ </td>
+<td>
+ <p>
+ This is not supported because local functions are implemented using
+ local classes and C++03
+ local classes cannot be templates.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <code class="computeroutput"><span class="keyword">explicit</span></code>
+ </p>
+ </td>
+<td>
+ <p>
+ No
+ </p>
+ </td>
+<td>
+ <p>
+ This is not supported because local functions are not constructors.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <code class="computeroutput"><span class="keyword">inline</span></code>
+ </p>
+ </td>
+<td>
+ <p>
+ Yes
+ </p>
+ </td>
+<td>
+ <p>
+ Local functions can be specified <code class="computeroutput"><span class="keyword">inline</span></code>
+ to improve the chances that C++03
+ standard compilers can optimize the local function call run-time
+ (but <code class="computeroutput"><span class="keyword">inline</span></code> local
+ functions cannot be passes as template parameters on C++03
+ standard compilers).
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <code class="computeroutput"><span class="keyword">extern</span></code>
+ </p>
+ </td>
+<td>
+ <p>
+ No
+ </p>
+ </td>
+<td>
+ <p>
+ This is not supported because local functions are always defined
+ locally within the enclosing scope and together with their declarations.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <code class="computeroutput"><span class="keyword">static</span></code>
+ </p>
+ </td>
+<td>
+ <p>
+ No
+ </p>
+ </td>
+<td>
+ <p>
+ This is not supported because local functions are not member functions.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <code class="computeroutput"><span class="keyword">virtual</span></code>
+ </p>
+ </td>
+<td>
+ <p>
+ No
+ </p>
+ </td>
+<td>
+ <p>
+ This is not supported because local functions are not member functions.
+ <sup>[<a name="boost_localfunction.Advanced_Topics.limitations__operators__etc_.f0" href="#ftn.boost_localfunction.Advanced_Topics.limitations__operators__etc_.f0" class="footnote">a</a>]</sup>
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <code class="literal"><span class="emphasis"><em>result-type</em></span></code>
+ </p>
+ </td>
+<td>
+ <p>
+ Yes
+ </p>
+ </td>
+<td>
+ <p>
+ This is supported (see the <a class="link" href="../">Tutorial</a>
+ section).
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <code class="literal"><span class="emphasis"><em>function-name</em></span></code>
+ </p>
+ </td>
+<td>
+ <p>
+ Yes
+ </p>
+ </td>
+<td>
+ <p>
+ Local functions are named and they can call themselves recursively
+ but they cannot be overloaded and they cannot be operators (see
+ the <a class="link" href="../">Tutorial</a> and <a class="link" href="../">Advanced Topics</a> sections).
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <code class="literal"><span class="emphasis"><em>parameter-list</em></span></code>
+ </p>
+ </td>
+<td>
+ <p>
+ Yes
+ </p>
+ </td>
+<td>
+ <p>
+ This is supported and it also supports the <code class="computeroutput"><span class="keyword">auto</span></code>
+ and <code class="computeroutput"><span class="keyword">register</span></code> storage
+ classifiers, default parameters, and binding of variables in scope
+ (see the <a class="link" href="../">Tutorial</a> and
+ <a class="link" href="../">Advanced Topics</a>
+ sections).
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ Trailing <code class="computeroutput"><span class="keyword">const</span></code> qualifier
+ </p>
+ </td>
+<td>
+ <p>
+ No
+ </p>
+ </td>
+<td>
+ <p>
+ This is not supported because local functions are not member functions.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ Trailing <code class="computeroutput"><span class="keyword">volatile</span></code>
+ qualifier
+ </p>
+ </td>
+<td>
+ <p>
+ No
+ </p>
+ </td>
+<td>
+ <p>
+ This is not supported because local functions are not member functions.
+ </p>
+ </td>
+</tr>
+</tbody>
+<tbody class="footnotes"><tr><td colspan="3"><div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.limitations__operators__etc_.f0" href="#boost_localfunction.Advanced_Topics.limitations__operators__etc_.f0" class="para">a</a>] </sup>
+ <span class="bold"><strong>Rationale.</strong></span> It would be possible
+ to make a local function class inherit from another local function
+ class. However, this "inheritance" feature is not implemented
+ because it seemed of <a href="http://lists.boost.org/Archives/boost/2010/09/170895.php" target="_top">no
+ use</a> given that local functions can be bound to one another
+ thus they can simply call each other directly without recurring
+ to dynamic binding or base function call.
+ </p></div></td></tr></tbody>
+</table></div>
+<h6>
+<a name="boost_localfunction.Advanced_Topics.limitations__operators__etc_.h0"></a>
+ <span><a name="boost_localfunction.Advanced_Topics.limitations__operators__etc_.operators"></a></span><a class="link" href="Advanced_Topics.html#boost_localfunction.Advanced_Topics.limitations__operators__etc_.operators">Operators</a>
+ </h6>
+<p>
+ Local functions cannot be operators. Naming a local function <code class="computeroutput"><span class="keyword">operator</span><span class="special">...</span></code>
+ will generate a compile-time error. <sup>[<a name="boost_localfunction.Advanced_Topics.limitations__operators__etc_.f1" href="#ftn.boost_localfunction.Advanced_Topics.limitations__operators__etc_.f1" class="footnote">23</a>]</sup>
+ </p>
+<p>
+ For example, the following code will <span class="bold"><strong>not</strong></span>
+ compile:
+ </p>
+<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">f</span><span class="special">()</span> <span class="special">{</span>
+ <span class="keyword">struct</span> <span class="identifier">point</span> <span class="special">{</span>
+ <span class="keyword">double</span> <span class="identifier">x</span><span class="special">;</span>
+ <span class="keyword">double</span> <span class="identifier">y</span><span class="special">;</span>
+ <span class="special">};</span>
+
+ <span class="keyword">bool</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">point</span><span class="special">&amp;</span> <span class="identifier">p</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">point</span><span class="special">&amp;</span> <span class="identifier">q</span><span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">p</span><span class="special">.</span><span class="identifier">x</span> <span class="special">==</span> <span class="identifier">q</span><span class="special">.</span><span class="identifier">x</span> <span class="special">&amp;&amp;</span> <span class="identifier">p</span><span class="special">.</span><span class="identifier">y</span> <span class="special">==</span> <span class="identifier">q</span><span class="special">.</span><span class="identifier">y</span><span class="special">;</span>
+ <span class="special">)</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="keyword">operator</span><span class="special">==)</span> <span class="comment">// Error: Cannot use `operator==`.</span>
+
+ <span class="special">...</span>
+<span class="special">}</span>
+</pre>
+<h6>
+<a name="boost_localfunction.Advanced_Topics.limitations__operators__etc_.h1"></a>
+ <span><a name="boost_localfunction.Advanced_Topics.limitations__operators__etc_.goto"></a></span><a class="link" href="Advanced_Topics.html#boost_localfunction.Advanced_Topics.limitations__operators__etc_.goto">Goto</a>
+ </h6>
+<p>
+ It is not possible to jump with a <code class="computeroutput"><span class="keyword">goto</span></code>
+ from within a local function, local block, or local exit to a label defined
+ in the enclosing scope.
+ </p>
+<p>
+ For example, the following will <span class="bold"><strong>not</strong></span> compile:
+ </p>
+<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">f</span><span class="special">()</span> <span class="special">{</span>
+ <span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">bool</span> <span class="identifier">error</span><span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span><span class="identifier">error</span><span class="special">)</span> <span class="keyword">goto</span> <span class="identifier">failure</span><span class="special">;</span> <span class="comment">// Error: Cannot jump to enclosing label `failure`.</span>
+ <span class="keyword">else</span> <span class="keyword">goto</span> <span class="identifier">success</span><span class="special">;</span> <span class="comment">// Ok: Can jump within enclosing scope.</span>
+
+ <span class="identifier">success</span><span class="special">:</span>
+ <span class="special">...</span>
+ <span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">f</span><span class="special">)</span>
+
+ <span class="identifier">f</span><span class="special">(</span><span class="keyword">true</span><span class="special">);</span>
+
+ <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+<span class="identifier">failure</span><span class="special">:</span>
+ <span class="keyword">return</span> <span class="special">-</span><span class="number">1</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+</div>
+<div class="footnotes">
+<br><hr width="100" align="left">
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.default_parameters.f0" href="#boost_localfunction.Advanced_Topics.default_parameters.f0" class="para">15</a>] </sup>
+ <span class="bold"><strong>Rationale.</strong></span> The assignment symbol <code class="computeroutput"><span class="special">=</span></code> cannot be used to specify default parameter
+ values because default values are not part of the parameter type so they
+ cannot be handled using template metaprogamming. Default parameter values
+ need to be separated from the rest of the parameter declaration using the
+ preprocessor. Specifically, this library needs to use preprocessor mataprogramming
+ to remove default values when constructing the local function type and
+ then to count the number of default values to provide the correct set of
+ call operators for the local functor. Therefore, the symbol <code class="computeroutput"><span class="special">=</span></code> cannot be used because it cannot be handled
+ by preprocessor metaprogramming (specifically, such a non-alphanumeric
+ symbol cannot be detected by preprocessor metaprogramming because it cannot
+ be concatenated by the preprocessor).
+ </p></div>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.default_parameters.f1" href="#boost_localfunction.Advanced_Topics.default_parameters.f1" class="para">16</a>] </sup>
+ The authors do not personally find the use of the <code class="computeroutput"><span class="identifier">WITH_DEFAULT</span></code>
+ macro more readable and they prefer to use the <code class="computeroutput"><span class="keyword">default</span></code>
+ "keyword" directly. Furthermore, <code class="computeroutput"><span class="identifier">WITH_DEFAULT</span></code>
+ need to be defined differently for compilers without variadic macros <code class="computeroutput"><span class="preprocessor">#define</span> <span class="identifier">WITH_DEFAULT</span>
+ <span class="special">(</span><span class="keyword">default</span><span class="special">)</span></code> so it can only be defined by programmers
+ based on the syntax they decide to use.
+ </p></div>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f0" href="#boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f0" class="para">17</a>] </sup>
+ <span class="bold"><strong>Rationale.</strong></span> This limitation derives from
+ the fact that <code class="computeroutput"><span class="identifier">BOOST_LOCAL_FUNCTION</span></code>
+ uses preprocessor token concatenation <code class="literal">##</code> to inspect
+ the parameter type token (to see if this token is a parameter or a bound
+ variable) and the C++ preprocessor does not allow to concatenate non-alphanumeric
+ tokens.
+ </p></div>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f1" href="#boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros.f1" class="para">18</a>] </sup>
+ <span class="bold"><strong>Rationale.</strong></span> Using variadic macros, this
+ extra set of parenthesis could be eliminated requiring only the parenthesis
+ to invoke the <code class="computeroutput"><span class="identifier">BOOST_IDENTITY_TYPE</span></code>
+ macro. However, this feature is currently not implemented and the double
+ parenthesis are always needed when invoking this macro.
+ </p></div>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.specifying_types.f0" href="#boost_localfunction.Advanced_Topics.specifying_types.f0" class="para">19</a>] </sup>
+ In the examples of this documentation, we specify bound variables, function
+ parameters, and result type in this order because that is the order used
+ by <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ lambda</a> functions. However, the library accepts bound variables,
+ function parameters, and the result type in any order.
+ </p></div>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.inlining.f0" href="#boost_localfunction.Advanced_Topics.inlining.f0" class="para">20</a>] </sup>
+ <span class="bold"><strong>Rationale.</strong></span> This library uses an indirect
+ function call via a function pointer in order to pass the local function
+ as a template parameter (see the <a class="link" href="../">Implementation</a>
+ section). No compiler has yet been observed to be able to inline function
+ calls when they use such indirect function pointer calls. Therefore,
+ inlined local functions do not use such indirect function pointer call
+ (so they are more likely to be optimized) but because of that they
+ cannot be passed as template parameters. The indirect function pointer
+ call is needed on C++03
+ but it is not needed on C++11
+ (see [N2657])
+ thus this library automatically generates local function calls that
+ can be inlined on C++11
+ compilers (even when the local function is not declared inline).
+ </p></div>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.recursion.f0" href="#boost_localfunction.Advanced_Topics.recursion.f0" class="para">21</a>] </sup>
+ <span class="bold"><strong>Rationale.</strong></span> This limitation comes from
+ the fact that a global functor used to pass the local function as a template
+ parameter (and eventually use it outside its declarations scope) does
+ not know the local function name so the local function name used for
+ recursive call cannot be set in the global functor. This limitation and
+ preventing the possibility for inlining is also the reason why local
+ function are not recursive unless programmers explicitly declare them
+ <code class="computeroutput"><span class="identifier">recursive</span></code>.
+ </p></div>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.storage_classifiers___auto__and__register__.f0" href="#boost_localfunction.Advanced_Topics.storage_classifiers___auto__and__register__.f0" class="para">22</a>] </sup>
+ The <code class="computeroutput"><span class="keyword">auto</span></code> storage classifier
+ is part of the C++03
+ standard and therefore supported by this library. However, the meaning
+ and usage of the <code class="computeroutput"><span class="keyword">auto</span></code> keyword
+ changed in C++11.
+ Therefore, use the <code class="computeroutput"><span class="keyword">auto</span></code> storage
+ classifier with the usual care in order to avoid writing C++03
+ code that might not work on C++11.
+ </p></div>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Advanced_Topics.limitations__operators__etc_.f1" href="#boost_localfunction.Advanced_Topics.limitations__operators__etc_.f1" class="para">23</a>] </sup>
+ <span class="bold"><strong>Rationale.</strong></span> This is the because a local
+ function name must be a valid local variable name (the local variable to
+ hold the local functor) and operators cannot be used as local variable
+ names.
+ </p></div>
+</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 &#169; 2009-2012 Lorenzo
+ Caminiti<p>
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="Tutorial.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><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="Examples.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>

Added: sandbox/closure/libs/local_function/doc/html/boost_localfunction/Alternatives.html
==============================================================================
--- (empty file)
+++ sandbox/closure/libs/local_function/doc/html/boost_localfunction/Alternatives.html 2012-01-21 13:28:36 EST (Sat, 21 Jan 2012)
@@ -0,0 +1,748 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
+<title>Appendix: Alternatives</title>
+<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
+<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;Boost.LocalFunction 1.0.0">
+<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;Boost.LocalFunction 1.0.0">
+<link rel="prev" href="Examples.html" title="Appendix: Examples">
+<link rel="next" href="No_Variadic_Macros.html" title="Annex: No Variadic Macros">
+</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">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="Examples.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><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="No_Variadic_Macros.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_localfunction.Alternatives"></a><a class="link" href="Alternatives.html" title="Appendix: Alternatives">Appendix: Alternatives</a>
+</h2></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section">Features</span></dt>
+<dt><span class="section">Performances</span></dt>
+</dl></div>
+<p>
+ This section compares the features offered by this library with similar features
+ offered by other libraries and by the new C++11
+ standard.
+ </p>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Alternatives.features"></a><a class="link" href="Alternatives.html#boost_localfunction.Alternatives.features" title="Features">Features</a>
+</h3></div></div></div>
+<p>
+ The following table compares local function features.
+ </p>
+<div class="informaltable"><table class="table">
+<colgroup>
+<col>
+<col>
+<col>
+<col>
+<col>
+<col>
+<col>
+</colgroup>
+<thead><tr>
+<th>
+ <p>
+ Local Function Feature
+ </p>
+ </th>
+<th>
+ <p>
+ Boost.Local (this library)
+ </p>
+ </th>
+<th>
+ <p>
+ Local Functor
+ </p>
+ </th>
+<th>
+ <p>
+ Global Functor (not local)
+ </p>
+ </th>
+<th>
+ <p>
+ __CPP0x_Lambda__ (not C++03)
+ </p>
+ </th>
+<th>
+ <p>
+ Boost.Lambda
+ </p>
+ </th>
+<th>
+ <p>
+ Boost.Phoenix
+ </p>
+ </th>
+</tr></thead>
+<tbody>
+<tr>
+<td>
+ <p>
+ <span class="emphasis"><em>Can be defined locally</em></span>
+ </p>
+ </td>
+<td>
+ <p>
+ Yes.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes.
+ </p>
+ </td>
+<td>
+ <p>
+ No. Therefore this not really an alternative implementation of
+ local functions but it is listed here just for comparison.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="emphasis"><em>Can be defined using C++ statement syntax</em></span>
+ </p>
+ </td>
+<td>
+ <p>
+ Yes. Plus eventual compiler errors follow the usual format of C++
+ statement errors.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes. Plus eventual compiler errors follow the usual format of C++
+ statement errors.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes. Plus eventual compiler errors follow the usual format of C++
+ statement errors.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes. Plus eventual compiler errors follow the usual format of C++
+ statement errors.
+ </p>
+ </td>
+<td>
+ <p>
+ No (it uses C++ <a href="http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Expression-template" target="_top">expression
+ template</a> syntax).
+ </p>
+ </td>
+<td>
+ <p>
+ No (it uses C++ <a href="http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Expression-template" target="_top">expression
+ template</a> syntax).
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="emphasis"><em>Can be defined within expressions</em></span>
+ </p>
+ </td>
+<td>
+ <p>
+ No. It can be defined only within declarations.
+ </p>
+ </td>
+<td>
+ <p>
+ No. It can be defined only within declarations.
+ </p>
+ </td>
+<td>
+ <p>
+ No. It can be defined only within declarations.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes (plus the local function can be unnamed).
+ </p>
+ </td>
+<td>
+ <p>
+ Yes (plus the local function can be unnamed).
+ </p>
+ </td>
+<td>
+ <p>
+ Yes (plus the local function can be unnamed).
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="emphasis"><em>Can be passed as template parameter (e.g., to STL algorithms)</em></span>
+ </p>
+ </td>
+<td>
+ <p>
+ Yes. The C++03
+ standard does not allow to pass local types as template parameters
+ (see [N2657])
+ but this library implements a "trick" to get around this
+ limitation (see the <a class="link" href="../">Implementation</a>
+ section).
+ </p>
+ </td>
+<td>
+ <p>
+ No on C++03
+ compilers (but yes on C++11
+ compilers and some compilers like MSVC 8.0, see [N2657]).
+ </p>
+ </td>
+<td>
+ <p>
+ Yes.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="emphasis"><em>Access variables in scope</em></span>
+ </p>
+ </td>
+<td>
+ <p>
+ Yes. The variable names are repeated in the function declaration
+ so they can be bound by value, by constant value, by reference,
+ and by constant reference (the object <code class="computeroutput"><span class="keyword">this</span></code>
+ can also be bound).
+ </p>
+ </td>
+<td>
+ <p>
+ No. Programmers must manually manage functor member variables and
+ explicitly specify their types to access variables in scope.
+ </p>
+ </td>
+<td>
+ <p>
+ No. Programmers must manually manage functor member variables and
+ explicitly specify their types to access variables in scope.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes. The variable names are repeated in the function declaration
+ (plus there is a short-hand syntax to bind all variables in scope
+ at once) so they can be bound by constant value and by reference
+ (the object <code class="computeroutput"><span class="keyword">this</span></code> can
+ also be bound). However, variables cannot be bound by constant
+ references and non-constant value (see below).
+ </p>
+ </td>
+<td>
+ <p>
+ Yes (variables in scope are accessible as usual within expressions).
+ </p>
+ </td>
+<td>
+ <p>
+ Yes (variables in scope are accessible as usual within expressions)
+ plus <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">phoenix</span><span class="special">::</span><span class="identifier">let</span></code> can be used to bind variables
+ by constant reference.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <span class="emphasis"><em>Polymorphic
+ in the unbound parameter types</em></span>
+ </p>
+ </td>
+<td>
+ <p>
+ No (local functions cannot be function templates).
+ </p>
+ </td>
+<td>
+ <p>
+ No (local classes cannot have member function templates).
+ </p>
+ </td>
+<td>
+ <p>
+ Yes.
+ </p>
+ </td>
+<td>
+ <p>
+ No (C++11
+ lambdas cannot be function templates).
+ </p>
+ </td>
+<td>
+ <p>
+ Yes.
+ </p>
+ </td>
+<td>
+ <p>
+ Yes.
+ </p>
+ </td>
+</tr>
+</tbody>
+</table></div>
+<h6>
+<a name="boost_localfunction.Alternatives.features.h0"></a>
+ <span><a name="boost_localfunction.Alternatives.features.comparison_with___cpp0x_lambda___functions"></a></span><a class="link" href="Alternatives.html#boost_localfunction.Alternatives.features.comparison_with___cpp0x_lambda___functions">Comparison
+ with __CPP0x_Lambda__ Functions</a>
+ </h6>
+<p>
+ __CPP0x_lambda__ functions have most of the features that __Boost_Local__
+ local functions have, key pro and cons of the two approaches are:
+ </p>
+<div class="itemizedlist"><ul class="itemizedlist" type="disc">
+<li class="listitem">
+ __CPP0x_lambda__ functions can be defined within expressions while __Boost_Local__
+ local functions can only be defined within declarations.
+ </li>
+<li class="listitem">
+ __CPP0x_lambda__ functions are only supported by the C++11
+ standard so they are not supported by all C++ compilers. __Boost_Local__
+ local functions use only C++03
+ compliant features so they are supported on all C++ compliant compilers.
+ </li>
+<li class="listitem">
+ __CPP0x_lambda__ functions do not allow to bind variables in scope by
+ constant reference or by non-constant value. Because a variable cannot
+ be bound by constant reference, __CPP0x_lambda__ functions can bind a
+ variable by constant only if the variable is copyable and the binding
+ requires a (potentially expensive) extra copy operation. Both constant
+ reference and non-constant value binding are instead supported by __Boost_Local__.
+ </li>
+</ul></div>
+<p>
+ For example, for non-copyable objects:
+ </p>
+<div class="informaltable"><table class="table">
+<colgroup><col></colgroup>
+<thead><tr>
+<th>
+ <p>
+ __CPP0x_Lambda__
+ </p>
+ </th>
+<th>
+ <p>
+ __Boost_Local__ __Variadic_Macro_Syntax__
+ </p>
+ </th>
+<th>
+ <p>
+ __Boost_Local__ __Sequencing_Macro_Syntax__
+ </p>
+ </th>
+</tr></thead>
+<tbody>
+<tr><td>
+ <p>
+ [noncopyable_0x_lambda_cpp
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ noncopyable_boost_local_va_cpp
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ noncopyable_boost_local_cpp
+ </p>
+ </td></tr>
+</tbody>
+</table></div>
+<p>
+ ]
+ </p>
+<p>
+ Or, for objects with expensive copy operations:
+ </p>
+<div class="informaltable"><table class="table">
+<colgroup><col></colgroup>
+<thead><tr>
+<th>
+ <p>
+ __CPP0x_Lambda__
+ </p>
+ </th>
+<th>
+ <p>
+ __Boost_Local__ __Variadic_Macro_Syntax__
+ </p>
+ </th>
+<th>
+ <p>
+ __Boost_Local__ __Sequencing_Macro_Syntax__
+ </p>
+ </th>
+</tr></thead>
+<tbody>
+<tr><td>
+ <p>
+ [expensive_copy_0x_lambda_cpp
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ expensive_copy_boost_local_va_cpp
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ expensive_copy_boost_local_cpp
+ </p>
+ </td></tr>
+</tbody>
+</table></div>
+<p>
+ ]
+ </p>
+<h6>
+<a name="boost_localfunction.Alternatives.features.h1"></a>
+ <span><a name="boost_localfunction.Alternatives.features.examples"></a></span><a class="link" href="Alternatives.html#boost_localfunction.Alternatives.features.examples">Examples</a>
+ </h6>
+<p>
+ The same example is rewritten here for all the different alternatives to
+ local functions so programmers can get a sense of the different syntaxes
+ and programming styles that the alternatives require. The following example
+ adds together all the elements of a vector using this library local functions:
+ </p>
+<div class="informaltable"><table class="table">
+<colgroup><col></colgroup>
+<thead><tr>
+<th>
+ <p>
+ __Variadic_Macro_Syntax__
+ </p>
+ </th>
+<th>
+ <p>
+ __Sequencing_Macro_Syntax__
+ </p>
+ </th>
+</tr></thead>
+<tbody>
+<tr><td>
+ <p>
+ [add_using_boost_local_va_cpp
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ add_using_boost_local_cpp
+ </p>
+ </td></tr>
+</tbody>
+</table></div>
+<p>
+ ]
+ </p>
+<p>
+ Or using C++ local functors:
+ </p>
+<p>
+ [add_using_local_functor_cpp]
+ </p>
+<p>
+ Or using C++ global functors (but these do not allow to define the function
+ locally so they are not a real alternative implementation of local functions):
+ </p>
+<p>
+ [add_using_global_functor_cpp]
+ </p>
+<p>
+ Or using __CPP0x_lambda__ functions (but not part of the C++03
+ standard):
+ </p>
+<p>
+ [add_using_cpp0x_lambda_cpp]
+ </p>
+<p>
+ Or using Boost.Lambda
+ functions:
+ </p>
+<p>
+ [add_using_boost_lambda_cpp]
+ </p>
+<p>
+ Or using Boost.Phoenix:
+ </p>
+<p>
+ [add_using_boost_phoenix_cpp]
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Alternatives.performances"></a><a class="link" href="Alternatives.html#boost_localfunction.Alternatives.performances" title="Performances">Performances</a>
+</h3></div></div></div>
+<p>
+ The following tables compare run-times, compile-times, and binary sizes for
+ the different alternatives presented so far for local functions.
+ </p>
+<p>
+ Overall, this library has compile-times and generates binary sizes similar
+ to the ones of the other approaches. This library run-times on C++03
+ compliant compilers (see "__Boost_Local__ Compliant" below) were
+ measured to be larger than other approaches when compiler optimization is
+ enabled (using <code class="computeroutput"><span class="identifier">bjam</span> <span class="identifier">release</span>
+ <span class="special">...</span></code>). However, on compilers that allow
+ to pass local types as template parameters (e.g., MSVC 8.0 or GCC 4.5.1 with
+ C++11 features
+ enabled, see also [N2657])
+ this library automatically generates optimized code that runs as fast as
+ the fastest of the other approaches (see "__Boost_Local__" below).
+ When this library local function is specified <code class="computeroutput"><span class="keyword">inline</span></code>
+ (see "__Boost_Local__ Inline For-Loop" below and the <a class="link" href="../">Advanced
+ Topics</a> section) its run-times are always comparable to both the "Local
+ Functor" and "Global Functor" approaches (but in this case
+ the local function cannot be portably passed as template parameter, see
+ [N2657],
+ so <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span></code> is replaced by a for-loop). Finally,
+ this library run-times are always among the fastest when no compiler optimization
+ is enabled (using <code class="computeroutput"><span class="identifier">bjam</span> <span class="identifier">debug</span>
+ <span class="special">...</span></code>).
+ </p>
+<div class="note"><table border="0" summary="Note">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../doc/src/images/note.png"></td>
+<th align="left">Note</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ The run-time performances of this library local functions are explained
+ because on C++03
+ compliant compilers (e.g., GCC 4.3.4) this library needs to use a function
+ pointer in order to pass the local function class as a template parameter
+ (see [N2657]
+ and the <a class="link" href="../">Implementation</a>
+ section). For all tested compilers, this function pointer prevents the
+ compiler optimization algorithms from inlining the local function calls.
+ Instead, the functors used by other approaches like "Boost.Lambda"
+ and "Boost.Phoenix"
+ have been observed to allow all tested compilers to inline all the function
+ calls for optimization. This run-time performance cost is not present on
+ compilers that allow to pass local types as template parameters (e.g.,
+ MSVC 8.0 or GCC 4.5.1 with C++11
+ features enabled) because this library does not have to use the extra function
+ pointer to implement the local function call (it directly passes the local
+ class type as template parameter).
+ </p></td></tr>
+</table></div>
+<p>
+ This run-time performance cost on C++03
+ compliant compilers might or might not be an issue depending on the performance
+ requirements of specific applications. For example, an application might
+ already be using a number of indirect function calls (function pointers,
+ virtual functions, etc) for which the overhead added by using the one extra
+ function pointer required by the local function call might not be noticeable
+ within the overall program run-time.
+ </p>
+<p>
+ Finally, note that only a very simple local function body with just a single
+ instruction was used for the anaylsis presented here (see the <code class="computeroutput"><span class="identifier">profile_</span><span class="special">...</span></code>
+ source files linked below). The authors have not studied how this library
+ and the other approaches will perform with respect to each other when a more
+ complex set of instructions is programmed for the local function body (e.g.,
+ <span class="emphasis"><em>if</em></span> a more complex set of instructions in the local function
+ body were to inhibit some compilers from inlining functor objects also other
+ approaches like Boost.Lambda
+ and Boost.Phoenix
+ <span class="emphasis"><em>could</em></span> start to show higher run-times even when optimization
+ is enabled).
+ </p>
+<div class="informaltable"><table class="table">
+<colgroup><col></colgroup>
+<thead><tr><th>
+ <p>
+ Legend, Source Files, and Commands
+ </p>
+ </th></tr></thead>
+<tbody>
+<tr><td>
+ <p>
+ <span class="inlinemediaobject"><img src="../../../example/profile_legend.png" width="1170" alt="profile_legend"></span>
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ The local function was called <code class="literal">1e8</code> times to add
+ together all the elements of a vector and the run-time was measured
+ using Boost.Chrono
+ averaging over <code class="literal">10</code> executions of the vector summation
+ (see source files profile_boost_local.cpp,
+ profile_boost_local_inline.cpp,
+ profile_local_functor.cpp,
+ profile_global_functor.cpp,
+ profile_0x_lambda.cpp,
+ profile_boost_lambda.cpp,
+ and profile_boost_phoenix.cpp).
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ The following commands were executed from the library example directory
+ to measure compile-time, binary size, and run-time respectively:
+</p>
+<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="special">&gt;</span> <span class="identifier">python</span> <span class="identifier">chrono</span><span class="special">.</span><span class="identifier">py</span> <span class="identifier">bjam</span> <span class="special">{</span><span class="identifier">release</span><span class="special">|</span><span class="identifier">debug</span><span class="special">}</span> <span class="special">&lt;</span><span class="identifier">PROGRAM</span><span class="special">&gt;</span> <span class="preprocessor"># compile</span><span class="special">-</span><span class="identifier">time</span>
+<span class="special">&gt;</span> <span class="identifier">size</span> <span class="special">&lt;</span><span class="identifier">PROGRAM</span><span class="special">&gt;</span> <span class="preprocessor"># binary</span> <span class="identifier">size</span> <span class="special">(</span><span class="identifier">Linux</span> <span class="keyword">and</span> <span class="identifier">Gygwin</span><span class="special">)</span>
+<span class="special">&gt;</span> <span class="special">&lt;</span><span class="identifier">PROGRAM</span><span class="special">&gt;</span> <span class="preprocessor"># run</span><span class="special">-</span><span class="identifier">time</span>
+</pre>
+<p>
+ </p>
+ </td></tr>
+</tbody>
+</table></div>
+<div class="informaltable"><table class="table">
+<colgroup><col></colgroup>
+<thead><tr><th>
+ <p>
+ GCC 4.5.1 With C++11
+ Lambdas and "Local Types as Template Parameters" (<code class="literal">bjam
+ cxxflags=-std=c++0x ...</code>) on Ubuntu Linux 10
+ </p>
+ </th></tr></thead>
+<tbody>
+<tr><td>
+ <p>
+ <span class="bold"><strong>Compiled with <code class="literal">bjam release ...</code>
+ for maximum optimization (<code class="literal">-O3 -finline-functions</code>)</strong></span>
+ <span class="inlinemediaobject"><img src="../../../example/profile_gcc-4.5.1-0x_release.png" width="1170" alt="profile_gcc-4.5.1-0x_release"></span>
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ <span class="bold"><strong>Compiled with <code class="literal">bjam debug ...</code>
+ for no optimization (<code class="literal">-O0 -fno-inline</code>)</strong></span>
+ <span class="inlinemediaobject"><img src="../../../example/profile_gcc-4.5.1-0x_debug.png" width="1170" alt="profile_gcc-4.5.1-0x_debug"></span>
+ </p>
+ </td></tr>
+</tbody>
+</table></div>
+<div class="informaltable"><table class="table">
+<colgroup><col></colgroup>
+<thead><tr><th>
+ <p>
+ MSVC 8.0 With "Local Types as Template Parameters" (Without
+ C++11
+ Lambdas) on Windows XP
+ </p>
+ </th></tr></thead>
+<tbody>
+<tr><td>
+ <p>
+ <span class="bold"><strong>Compiled with <code class="literal">bjam release ...</code>
+ for maximum optimization (<code class="literal">/O2 /Ob2</code>)</strong></span>
+ <span class="inlinemediaobject"><img src="../../../example/profile_msvc-8.0_release.png" width="1170" alt="profile_msvc-8.0_release"></span>
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ <span class="bold"><strong>Compiled with <code class="literal">bjam debug ...</code>
+ for no optimization (<code class="literal">/Od /Ob0</code>)</strong></span> <span class="inlinemediaobject"><img src="../../../example/profile_msvc-8.0_debug.png" width="1170" alt="profile_msvc-8.0_debug"></span>
+ </p>
+ </td></tr>
+</tbody>
+</table></div>
+<div class="informaltable"><table class="table">
+<colgroup><col></colgroup>
+<thead><tr><th>
+ <p>
+ GCC 4.3.4 With C++03
+ Only (Without C++11
+ Lambdas and Without "Local Types as Template Parameters) on
+ Cygwin
+ </p>
+ </th></tr></thead>
+<tbody>
+<tr><td>
+ <p>
+ <span class="bold"><strong>Compiled with <code class="literal">bjam release ...</code>
+ for maximum optimization (<code class="literal">-O3 -finline-functions</code>)</strong></span>
+ <span class="inlinemediaobject"><img src="../../../example/profile_gcc-4.3.4_release.png" width="1170" alt="profile_gcc-4.3.4_release"></span>
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ <span class="bold"><strong>Compiled with <code class="literal">bjam debug ...</code>
+ for no optimization (<code class="literal">-O0 -fno-inline</code>)</strong></span>
+ <span class="inlinemediaobject"><img src="../../../example/profile_gcc-4.3.4_debug.png" width="1170" alt="profile_gcc-4.3.4_debug"></span>
+ </p>
+ </td></tr>
+</tbody>
+</table></div>
+</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 &#169; 2009-2012 Lorenzo
+ Caminiti<p>
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="Examples.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><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="No_Variadic_Macros.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>

Added: sandbox/closure/libs/local_function/doc/html/boost_localfunction/Bibliography.html
==============================================================================
--- (empty file)
+++ sandbox/closure/libs/local_function/doc/html/boost_localfunction/Bibliography.html 2012-01-21 13:28:36 EST (Sat, 21 Jan 2012)
@@ -0,0 +1,69 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
+<title>Bibliography</title>
+<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
+<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;Boost.LocalFunction 1.0.0">
+<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;Boost.LocalFunction 1.0.0">
+<link rel="prev" href="Release_Notes.html" title="Release Notes">
+<link rel="next" href="Acknowledgments.html" title="Acknowledgments">
+</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">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="Release_Notes.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><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="Acknowledgments.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_localfunction.Bibliography"></a><a class="link" href="Bibliography.html" title="Bibliography">Bibliography</a>
+</h2></div></div></div>
+<p>
+ This section lists all the bibliographic references cited by this documentation.
+ </p>
+<p>
+ [N2511]
+ Alisdair Meredith. <span class="emphasis"><em>Named Lambdas and Local Functions.</em></span>
+ The C++ Standards Committee, document no. N2511=08-0021, 2008.
+ </p>
+<p>
+ [N2529]
+ Jaakko Jarvi, John Freeman, Lawrence Crowl. <span class="emphasis"><em>Lambda Expressions and
+ Closures: Wording for Monomorphic Lambdas (Revision 3).</em></span> The C++
+ Standards Committee, document no. N2529=08-0039, 2008.
+ </p>
+<p>
+ [N2550]
+ Jaakko Jarvi, John Freeman, Lawrence Crowl. <span class="emphasis"><em>Lambda Expressions and
+ Closures: Wording for Monomorphic Lambdas (Revision 4).</em></span> The C++
+ Standards Committee, document no. N2550=08-0060, 2008.
+ </p>
+<p>
+ [N2657]
+ John Spicer. <span class="emphasis"><em>Local and Unamed Types as Template Arguments.</em></span>
+ The C++ Standard Committee, document no. N2657=08-0167, 2008.
+ </p>
+</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 &#169; 2009-2012 Lorenzo
+ Caminiti<p>
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="Release_Notes.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><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="Acknowledgments.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>

Added: sandbox/closure/libs/local_function/doc/html/boost_localfunction/Examples.html
==============================================================================
--- (empty file)
+++ sandbox/closure/libs/local_function/doc/html/boost_localfunction/Examples.html 2012-01-21 13:28:36 EST (Sat, 21 Jan 2012)
@@ -0,0 +1,461 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
+<title>Appendix: Examples</title>
+<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
+<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;Boost.LocalFunction 1.0.0">
+<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;Boost.LocalFunction 1.0.0">
+<link rel="prev" href="Advanced_Topics.html" title="Advanced Topics">
+<link rel="next" href="Alternatives.html" title="Appendix: Alternatives">
+</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">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="Advanced_Topics.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><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="Alternatives.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_localfunction.Examples"></a><a class="link" href="Examples.html" title="Appendix: Examples">Appendix: Examples</a>
+</h2></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"><a href="Examples.html#boost_localfunction.Examples.gcc_lambdas__without_c__11_">GCC
+ Lambdas (Without C++11)</a></span></dt>
+<dt><span class="section"><a href="Examples.html#boost_localfunction.Examples.constant_blocks">Constant
+ Blocks</a></span></dt>
+<dt><span class="section">Scope Exits</span></dt>
+<dt><span class="section"><a href="Examples.html#boost_localfunction.Examples.gcc_nested_functions">GCC
+ Nested Functions</a></span></dt>
+<dt><span class="section">N-Papers</span></dt>
+</dl></div>
+<p>
+ This sections lists some (interesting) examples that use this library features.
+ </p>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Examples.gcc_lambdas__without_c__11_"></a><a class="link" href="Examples.html#boost_localfunction.Examples.gcc_lambdas__without_c__11_" title="GCC Lambdas (Without C++11)">GCC
+ Lambdas (Without C++11)</a>
+</h3></div></div></div>
+<p>
+ Combing local functions with the <a href="http://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html" target="_top">statement
+ expression</a> GCC extension, it is possible to implement lambda functions
+ for GCC compilers even without C++11
+ support.
+ </p>
+<div class="warning"><table border="0" summary="Warning">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../doc/src/images/warning.png"></td>
+<th align="left">Warning</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ This code only works on compilers that support the statement expression
+ GCC extension or that support <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ lambda</a> functions.
+ </p></td></tr>
+</table></div>
+<p>
+ For example (see also "gcc_lambda.cpp" and "gcc_lambda_cpp11.cpp"):
+ </p>
+<div class="informaltable"><table class="table">
+<colgroup>
+<col>
+<col>
+</colgroup>
+<thead><tr>
+<th>
+ <p>
+ With Local Functions (GCC only)
+ </p>
+ </th>
+<th>
+ <p>
+ C++11 Lambdas
+ </p>
+ </th>
+</tr></thead>
+<tbody><tr>
+<td>
+ <p>
+</p>
+<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="keyword">int</span> <span class="identifier">val</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span>
+<span class="keyword">int</span> <span class="identifier">nums</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span><span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">};</span>
+<span class="keyword">int</span><span class="special">*</span> <span class="identifier">end</span> <span class="special">=</span> <span class="identifier">nums</span> <span class="special">+</span> <span class="number">3</span><span class="special">;</span>
+
+<span class="keyword">int</span><span class="special">*</span> <span class="identifier">iter</span> <span class="special">=</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">find_if</span><span class="special">(</span><span class="identifier">nums</span><span class="special">,</span> <span class="identifier">end</span><span class="special">,</span>
+ <span class="identifier">GCC_LAMBDA</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">bind</span> <span class="identifier">val</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">num</span><span class="special">,</span> <span class="keyword">return</span> <span class="keyword">bool</span><span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">num</span> <span class="special">==</span> <span class="identifier">val</span><span class="special">;</span>
+ <span class="special">}</span> <span class="identifier">GCC_LAMBDA_END</span>
+<span class="special">);</span>
+</pre>
+<p>
+ </p>
+ </td>
+<td>
+ <p>
+</p>
+<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="keyword">int</span> <span class="identifier">val</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span>
+<span class="keyword">int</span> <span class="identifier">nums</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span><span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">};</span>
+<span class="keyword">int</span><span class="special">*</span> <span class="identifier">end</span> <span class="special">=</span> <span class="identifier">nums</span> <span class="special">+</span> <span class="number">3</span><span class="special">;</span>
+
+<span class="keyword">int</span><span class="special">*</span> <span class="identifier">iter</span> <span class="special">=</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">find_if</span><span class="special">(</span><span class="identifier">nums</span><span class="special">,</span> <span class="identifier">end</span><span class="special">,</span>
+ <span class="special">[</span><span class="identifier">val</span><span class="special">](</span><span class="keyword">int</span> <span class="identifier">num</span><span class="special">)</span> <span class="special">-&gt;</span> <span class="keyword">bool</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">num</span> <span class="special">==</span> <span class="identifier">val</span><span class="special">;</span>
+ <span class="special">}</span>
+<span class="special">);</span>
+</pre>
+<p>
+ </p>
+ </td>
+</tr></tbody>
+</table></div>
+<p>
+ The macros are defined in "gcc_lambda.hpp".
+ </p>
+<p>
+ This is possible because GCC statement expressions allow to put declaration
+ statements within expressions and therefore to declare a local function within
+ an expression. The macros automatically detect if the compiler supports
+ <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ lambda</a> functions in which case the implementation uses native lambdas
+ instead of local functions. However, <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ lambda</a> functions do not support constant binding so it is best to
+ only use <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">bind</span>
+ <span class="identifier">variable</span></code> (same as <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ lambda</a> <code class="computeroutput"><span class="special">=</span><span class="identifier">variable</span></code>)
+ and <code class="computeroutput"><span class="identifier">bind</span><span class="special">&amp;</span>
+ <span class="identifier">variable</span></code> (same as <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ lambda</a> <code class="computeroutput"><span class="special">&amp;</span><span class="identifier">variable</span></code>)
+ because these have the exact same semantic between the local function and
+ native lambda implementation. Unfortunately, the <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ lambda</a> short-hand binds <code class="computeroutput"><span class="special">&amp;</span></code>
+ and <code class="computeroutput"><span class="special">=</span></code> (which automatically bind
+ all variables in scope either by reference or value) are not supported by
+ the macros because they are not supported by the local function implementation.
+ Finally, the result type <code class="computeroutput"><span class="keyword">return</span> </code><code class="literal"><span class="emphasis"><em>result-type</em></span></code>
+ is optional and it is assumed <code class="computeroutput"><span class="keyword">void</span></code>
+ when it is not specified (as with <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ lambda</a> functions).
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Examples.constant_blocks"></a><a class="link" href="Examples.html#boost_localfunction.Examples.constant_blocks" title="Constant Blocks">Constant
+ Blocks</a>
+</h3></div></div></div>
+<p>
+ It is possible to use local functions to check assertions between variables
+ that are constant within the assertion expression. This is advantageous because
+ assertions are not supposed to change the state of the program and ideally
+ the compiler will not compile assertions that modify variables.
+ </p>
+<p>
+ For example, consider the following assertion where by mistake we programmed
+ <code class="computeroutput"><span class="keyword">operator</span><span class="special">=</span></code>
+ instead of <code class="computeroutput"><span class="keyword">operator</span><span class="special">==</span></code>:
+ </p>
+<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">x</span> <span class="special">=</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">y</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span>
+<span class="identifier">assert</span><span class="special">(</span><span class="identifier">x</span> <span class="special">=</span> <span class="identifier">y</span><span class="special">);</span> <span class="comment">// Mistakenly `=` instead of `==`.</span>
+</pre>
+<p>
+ Ideally this code will not compile instead this example not only compiles
+ but the assertion even passes the run-time check and no error is generated
+ at all. The [N1613]
+ paper introduced the idea of a <span class="emphasis"><em>const-block</em></span> which could
+ be used to wrap the assertion above and catch the mistake at compile-time.
+ Similarly to [N1613]
+ const-blocks, the following code will generate a compile-time error when
+ <code class="computeroutput"><span class="keyword">operator</span><span class="special">=</span></code>
+ is mistakenly used instead of <code class="computeroutput"><span class="keyword">operator</span><span class="special">==</span></code> because both <code class="computeroutput"><span class="identifier">x</span></code>
+ and <code class="computeroutput"><span class="identifier">y</span></code> are constants within
+ the block of code performing the assertion (see also "const_block.cpp"):
+ </p>
+<div class="informaltable"><table class="table">
+<colgroup>
+<col>
+<col>
+</colgroup>
+<thead><tr>
+<th>
+ <p>
+ With Local Functions
+ </p>
+ </th>
+<th>
+ <p>
+ N1613 Constant Block
+ </p>
+ </th>
+</tr></thead>
+<tbody><tr>
+<td>
+ <p>
+</p>
+<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="keyword">int</span> <span class="identifier">x</span> <span class="special">=</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">y</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span>
+<span class="identifier">CONST_BLOCK</span><span class="special">(</span><span class="identifier">x</span><span class="special">,</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span> <span class="comment">// Constant block.</span>
+ <span class="identifier">assert</span><span class="special">(</span><span class="identifier">x</span> <span class="special">=</span> <span class="identifier">y</span><span class="special">);</span> <span class="comment">// Compiler error.</span>
+<span class="special">}</span> <span class="identifier">CONST_BLOCK_END</span>
+</pre>
+<p>
+ </p>
+ </td>
+<td>
+ <p>
+</p>
+<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="keyword">int</span> <span class="identifier">x</span> <span class="special">=</span> <span class="number">1</span><span class="special">,</span> <span class="identifier">y</span> <span class="special">=</span> <span class="number">2</span><span class="special">;</span>
+<span class="keyword">const</span> <span class="special">{</span> <span class="comment">// Constant block.</span>
+ <span class="identifier">assert</span><span class="special">(</span><span class="identifier">x</span> <span class="special">=</span> <span class="identifier">y</span><span class="special">);</span> <span class="comment">// Compiler error.</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+ </td>
+</tr></tbody>
+</table></div>
+<p>
+ The macros are defined in "const_block.hpp".
+ </p>
+<p>
+ The constant block macros are implemented using a local function which binds
+ by constant reference <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">bind</span><span class="special">&amp;</span></code>
+ all the specified variables, it executes the <code class="computeroutput"><span class="identifier">assert</span></code>
+ instruction in local function body, and the local function is then called
+ immediately after it is defined. More in general, constant blocks can be
+ used to evaluate any instruction (not just assertions) within a block were
+ all specified variables are constant.
+ </p>
+<p>
+ Unfortunately, constant blocks cannot be implemented with <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ lambda</a> functions because these do not support constant binding. Ideally,
+ <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ lambda</a> functions would allow to bind variables also using <code class="computeroutput"><span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">variable</span></code> (constant reference) and <code class="computeroutput"><span class="keyword">const</span><span class="special">&amp;</span></code>
+ (all variables by constant reference). Variables bound by value using <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ lambda</a> functions (<code class="computeroutput"><span class="identifier">variable</span></code>,
+ <code class="computeroutput"><span class="special">=</span><span class="identifier">variable</span></code>,
+ and <code class="computeroutput"><span class="special">=</span></code>) are constant but they
+ are required to be <code class="computeroutput"><span class="identifier">CopyConstructible</span></code>
+ and they introduce potentially expensive copy operations.
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Examples.scope_exits"></a><a class="link" href="Examples.html#boost_localfunction.Examples.scope_exits" title="Scope Exits">Scope Exits</a>
+</h3></div></div></div>
+<p>
+ Scope exits allow to execute arbitrary code at the exit of the enclosing
+ scope and they are provided by the Boost.ScopeExit
+ library.
+ </p>
+<p>
+ For curiosity, here we show how to re-implement scope exits using local functions.
+ One small advantage of scope exits that use local functions is that they
+ support constant binding. Boost.ScopeExit
+ does not directly support constant binding (however, it is always possible
+ to introduce an extra <code class="computeroutput"><span class="keyword">const</span></code>
+ local variable, assign it to the value to bind, and then bind the <code class="computeroutput"><span class="keyword">const</span></code> variable so to effectively have constant
+ binding with Boost.ScopeExit
+ as well). In general, the authors recommend to use Boost.ScopeExit
+ instead of the code listed here whenever possible.
+ </p>
+<p>
+ The following example binds <code class="computeroutput"><span class="identifier">p</span></code>
+ by constant reference so this variable cannot be modified within the scope
+ exit body but it is not copied and it will present the value it has at the
+ exit of the enclosing scope and not at the scope exit declaration (see also
+ "scope_exit.cpp"):
+ </p>
+<div class="informaltable"><table class="table">
+<colgroup>
+<col>
+<col>
+</colgroup>
+<thead><tr>
+<th>
+ <p>
+ With Local Functions
+ </p>
+ </th>
+<th>
+ <p>
+ Boost.ScopeExit
+ </p>
+ </th>
+</tr></thead>
+<tbody><tr>
+<td>
+ <p>
+</p>
+<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">person</span><span class="special">&amp;</span> <span class="identifier">p</span> <span class="special">=</span> <span class="identifier">persons_</span><span class="special">.</span><span class="identifier">back</span><span class="special">();</span>
+<span class="identifier">person</span><span class="special">::</span><span class="identifier">evolution_t</span> <span class="identifier">checkpoint</span> <span class="special">=</span> <span class="identifier">p</span><span class="special">.</span><span class="identifier">evolution_</span><span class="special">;</span>
+
+<span class="identifier">SCOPE_EXIT</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">bind</span> <span class="identifier">checkpoint</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">bind</span><span class="special">&amp;</span> <span class="identifier">p</span><span class="special">,</span> <span class="identifier">bind</span> <span class="identifier">this_</span><span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span><span class="identifier">checkpoint</span> <span class="special">==</span> <span class="identifier">p</span><span class="special">.</span><span class="identifier">evolution_</span><span class="special">)</span> <span class="identifier">this_</span><span class="special">-&gt;</span><span class="identifier">persons_</span><span class="special">.</span><span class="identifier">pop_back</span><span class="special">();</span>
+<span class="special">}</span> <span class="identifier">SCOPE_EXIT_END</span>
+</pre>
+<p>
+ </p>
+ </td>
+<td>
+ <p>
+</p>
+<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><span class="identifier">person</span><span class="special">&amp;</span> <span class="identifier">p</span> <span class="special">=</span> <span class="identifier">persons_</span><span class="special">.</span><span class="identifier">back</span><span class="special">();</span>
+<span class="identifier">person</span><span class="special">::</span><span class="identifier">evolution_t</span> <span class="identifier">checkpoint</span> <span class="special">=</span> <span class="identifier">p</span><span class="special">.</span><span class="identifier">evolution_</span><span class="special">;</span>
+
+<span class="identifier">BOOST_SCOPE_EXIT</span><span class="special">(</span><span class="identifier">checkpoint</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">p</span><span class="special">,</span> <span class="identifier">this_</span><span class="special">)</span> <span class="special">{</span> <span class="comment">// Or extra variable `const_p`.</span>
+ <span class="keyword">if</span> <span class="special">(</span><span class="identifier">checkpoint</span> <span class="special">==</span> <span class="identifier">p</span><span class="special">.</span><span class="identifier">evolution_</span><span class="special">)</span> <span class="identifier">this_</span><span class="special">-&gt;</span><span class="identifier">persons_</span><span class="special">.</span><span class="identifier">pop_back</span><span class="special">();</span>
+<span class="special">}</span> <span class="identifier">BOOST_SCOPE_EXIT_END</span>
+</pre>
+<p>
+ </p>
+ </td>
+</tr></tbody>
+</table></div>
+<p>
+ The macros are defined in "scope_exit.hpp".
+ </p>
+<p>
+ The scope exit macros are implemented by passing a local function to the
+ constructor of the following object:
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">scope_exit</span> <span class="special">{</span>
+ <span class="identifier">scope_exit</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span><span class="special">&lt;</span><span class="keyword">void</span> <span class="special">(</span><span class="keyword">void</span><span class="special">)&gt;</span> <span class="identifier">f</span><span class="special">):</span> <span class="identifier">f_</span><span class="special">(</span><span class="identifier">f</span><span class="special">)</span> <span class="special">{}</span>
+ <span class="special">~</span><span class="identifier">scope_exit</span><span class="special">(</span><span class="keyword">void</span><span class="special">)</span> <span class="special">{</span> <span class="identifier">f_</span><span class="special">();</span> <span class="special">}</span>
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span><span class="special">&lt;</span><span class="keyword">void</span> <span class="special">(</span><span class="keyword">void</span><span class="special">)&gt;</span> <span class="identifier">f_</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ </p>
+<p>
+ The object variable is declared locally within the enclosing scope so the
+ object destructor will be invoked at the exit of the enclosing scope and
+ it will in turn call the local function. The scope exit local function has
+ no parameter and <code class="computeroutput"><span class="keyword">void</span></code> result
+ type but it supports binding and constant binding.
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Examples.gcc_nested_functions"></a><a class="link" href="Examples.html#boost_localfunction.Examples.gcc_nested_functions" title="GCC Nested Functions">GCC
+ Nested Functions</a>
+</h3></div></div></div>
+<p>
+ The GCC C compiler supports local functions under the name of <a href="http://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html" target="_top">nested
+ functions</a>. Nested functions are exclusively a C extension of the
+ GCC compiler (they are not supported for C++ not even by the GCC compiler,
+ and they are not part of any C or C++ standard, nor they are supported by
+ other compilers like MSVC).
+ </p>
+<p>
+ The following examples are taken form the GCC nested function documentation
+ but are programmed using this library:
+ </p>
+<div class="informaltable"><table class="table">
+<colgroup><col></colgroup>
+<thead><tr><th>
+ <p>
+ Files
+ </p>
+ </th></tr></thead>
+<tbody>
+<tr><td>
+ <p>
+ "gcc_square.cpp"
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ "gcc_access.cpp"
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ "gcc_store.cpp"
+ </p>
+ </td></tr>
+</tbody>
+</table></div>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Examples.n_papers"></a><a class="link" href="Examples.html#boost_localfunction.Examples.n_papers" title="N-Papers">N-Papers</a>
+</h3></div></div></div>
+<p>
+ The following examples are taken from a number of N-papers and programmed
+ using this library.
+ </p>
+<div class="informaltable"><table class="table">
+<colgroup>
+<col>
+<col>
+</colgroup>
+<thead><tr>
+<th>
+ <p>
+ Files
+ </p>
+ </th>
+<th>
+ <p>
+ Notes
+ </p>
+ </th>
+</tr></thead>
+<tbody>
+<tr>
+<td>
+ <p>
+ "n2550_find_if.cpp"
+ </p>
+ </td>
+<td>
+ <p>
+ This example is adapted from [N2550]
+ (<a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ lambda</a> functions): It passes a local function to the STL
+ algorithm <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">find_if</span></code>.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ "n2529_this.cpp"
+ </p>
+ </td>
+<td>
+ <p>
+ This example is adapted from [N2529]
+ (<a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ lambda</a> functions): It binds the object in scope <code class="computeroutput"><span class="keyword">this</span></code> to a local function.
+ </p>
+ </td>
+</tr>
+</tbody>
+</table></div>
+</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 &#169; 2009-2012 Lorenzo
+ Caminiti<p>
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="Advanced_Topics.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><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="Alternatives.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>

Added: sandbox/closure/libs/local_function/doc/html/boost_localfunction/Getting_Started.html
==============================================================================
--- (empty file)
+++ sandbox/closure/libs/local_function/doc/html/boost_localfunction/Getting_Started.html 2012-01-21 13:28:36 EST (Sat, 21 Jan 2012)
@@ -0,0 +1,200 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
+<title>Getting Started</title>
+<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
+<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;Boost.LocalFunction 1.0.0">
+<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;Boost.LocalFunction 1.0.0">
+<link rel="prev" href="../index.html" title="Chapter&#160;1.&#160;Boost.LocalFunction 1.0.0">
+<link rel="next" href="Tutorial.html" title="Tutorial">
+</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">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="../index.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><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="Tutorial.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_localfunction.Getting_Started"></a><a class="link" href="Getting_Started.html" title="Getting Started">Getting Started</a>
+</h2></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"><a href="Getting_Started.html#boost_localfunction.Getting_Started.this_documentation">This
+ Documentation</a></span></dt>
+<dt><span class="section"><a href="Getting_Started.html#boost_localfunction.Getting_Started.compilers_and_platforms">Compilers
+ and Platforms</a></span></dt>
+<dt><span class="section">Installation</span></dt>
+<dt><span class="section"><a href="Getting_Started.html#boost_localfunction.Getting_Started.compile_time_configuration">Compile-Time
+ Configuration</a></span></dt>
+</dl></div>
+<p>
+ This section explains how to setup a system to use this library.
+ </p>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Getting_Started.this_documentation"></a><a class="link" href="Getting_Started.html#boost_localfunction.Getting_Started.this_documentation" title="This Documentation">This
+ Documentation</a>
+</h3></div></div></div>
+<p>
+ Programmers should have enough knowledge to use this library after reading
+ the <a class="link" href="../">Introduction</a>, <a class="link" href="../">Getting
+ Started</a>, and <a class="link" href="../">Tutorial</a>
+ sections. The <a class="link" href="../">Advanced Topics</a>
+ and Reference sections can be consulted
+ at a later point to gain a more advanced knowledge of the library. All the
+ other sections of this documentation are optional.
+ </p>
+<p>
+ Some footnotes are marked by the word "<span class="bold"><strong>Rationale</strong></span>".
+ They explain reasons behind decisions made during the design and implementation
+ of this library.
+ </p>
+<p>
+ In some of the examples presented in this documentation, the Boost.Test
+ macro <code class="computeroutput"><span class="identifier">BOOST_CHECK</span></code> is used
+ equivalently to <code class="computeroutput"><span class="identifier">assert</span></code> and
+ Boost.Test
+ <code class="computeroutput"><span class="identifier">BOOST_AUTO_TEST_CASE</span></code> equivalently
+ to <code class="computeroutput"><span class="identifier">main</span></code>. <sup>[<a name="boost_localfunction.Getting_Started.this_documentation.f0" href="#ftn.boost_localfunction.Getting_Started.this_documentation.f0" class="footnote">1</a>]</sup>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Getting_Started.compilers_and_platforms"></a><a class="link" href="Getting_Started.html#boost_localfunction.Getting_Started.compilers_and_platforms" title="Compilers and Platforms">Compilers
+ and Platforms</a>
+</h3></div></div></div>
+<p>
+ The implementation of this library uses preprocessor and template metaprogramming
+ (as supported by Boost.Preprocessor
+ and Boost.MPL),
+ templates with partial specializations and function pointers (similarly to
+ Boost.Function).
+ As a consequence, this library is fairly demanding on compilers' compliance
+ with the C++03
+ standard. At present, this library has been successfully compiled and tested
+ on the following compilers and platforms:
+ </p>
+<div class="orderedlist"><ol class="orderedlist" type="1">
+<li class="listitem">
+ GNU Compiler Collection (GCC) 4.5.1 (with and without C++11
+ features enabled) on Ubuntu Linux 10.
+ </li>
+<li class="listitem">
+ GCC 4.3.4 on Cygwin.
+ </li>
+<li class="listitem">
+ Miscrosoft Visual Studio Compiler (MSVC) 8.0 on Windows XP and Windows
+ 7.
+ </li>
+</ol></div>
+<p>
+ This library has not yet been tested on any other compiler or platform.
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Getting_Started.installation"></a><a class="link" href="Getting_Started.html#boost_localfunction.Getting_Started.installation" title="Installation">Installation</a>
+</h3></div></div></div>
+<p>
+ This library is composed of header files only. Therefore there is no pre-compiled
+ object file which needs to be installed. Programmers can simply instruct
+ the C++ compiler where to find the library header files (<code class="computeroutput"><span class="special">-</span><span class="identifier">I</span></code> option for GCC, <code class="computeroutput"><span class="special">/</span><span class="identifier">I</span></code> option for MSVC, etc) and they can start
+ compiling the code that uses this library.
+ </p>
+<p>
+ This library implementation uses a number of Boost
+ libraries among which: Boost.Preprocessor,
+ Boost.ScopeExit,
+ Boost.Typeof,
+ Boost.TypeTraits,
+ and Boost.MPL.
+ These Boost libraries must be
+ properly installed on your system in order for this library to work.
+ </p>
+<p>
+ The followings are part of the library private API, they are not documented,
+ and they should not be directly used by programmers: <sup>[<a name="boost_localfunction.Getting_Started.installation.f0" href="#ftn.boost_localfunction.Getting_Started.installation.f0" class="footnote">2</a>]</sup>
+ </p>
+<div class="itemizedlist"><ul class="itemizedlist" type="disc">
+<li class="listitem">
+ Any symbol defined by files within the <code class="computeroutput"><span class="string">"boost/local_function/aux_/"</span></code>
+ or <code class="computeroutput"><span class="string">"boost/local_function/detail"</span></code>
+ directories (these header files should not be directly included by programmers).
+ </li>
+<li class="listitem">
+ Any symbol prefixed by <code class="computeroutput"><span class="identifier">BOOST_LOCAL_FUNCTION_AUX_</span><span class="special">...</span></code> or <code class="computeroutput"><span class="identifier">BOOST_LOCAL_FUNCTION_DETAIL_</span><span class="special">...</span></code> (regardless of its namespace).
+ </li>
+<li class="listitem">
+ Any symbol within the <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">local_function</span><span class="special">::</span><span class="identifier">aux</span></code>
+ or <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">local_function</span><span class="special">::</span><span class="identifier">detail</span></code> namespace.
+ </li>
+<li class="listitem">
+ Any symbol prefixed by <code class="computeroutput"><span class="identifier">boost_local_function_aux_</span><span class="special">...</span></code> or <code class="computeroutput"><span class="identifier">boost_local_function_detail_</span><span class="special">...</span></code> (regardless of its namespace).
+ </li>
+</ul></div>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Getting_Started.compile_time_configuration"></a><a class="link" href="Getting_Started.html#boost_localfunction.Getting_Started.compile_time_configuration" title="Compile-Time Configuration">Compile-Time
+ Configuration</a>
+</h3></div></div></div>
+<p>
+ Some of the library behaviour can be changed at compile-time by defining
+ special <span class="emphasis"><em>configuration macros</em></span>. If a configuration macro
+ is left undefined, the library will use an appropriate default value for
+ it.
+ </p>
+<p>
+ All configuration macros have names prefixed by <code class="computeroutput"><span class="identifier">BOOST_LOCAL_CONFIG_</span><span class="special">...</span></code> (see the Reference
+ section). It is strongly recommended not to change the library configuration
+ macro definitions unless strictly necessary.
+ </p>
+</div>
+<div class="footnotes">
+<br><hr width="100" align="left">
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Getting_Started.this_documentation.f0" href="#boost_localfunction.Getting_Started.this_documentation.f0" class="para">1</a>] </sup>
+ <span class="bold"><strong>Rationale.</strong></span> Using Boost.Test
+ allows to add the documentation examples to the library regression test
+ suite so to make sure that the listed examples always compile and run correctly.
+ </p></div>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Getting_Started.installation.f0" href="#boost_localfunction.Getting_Started.installation.f0" class="para">2</a>] </sup>
+ <span class="bold"><strong>Rationale.</strong></span> This library concatenates symbols
+ specified by the programmers (e.g., the local function name) with other
+ symbols (e.g., special prefixes or preprocessor line numbers) to make internal
+ symbols with unique names to avoid name clashes. These symbols are separated
+ by the letter "<code class="computeroutput"><span class="identifier">X</span></code>"
+ when they are concatenated so they read more easily during debugging. The
+ underscore character "<code class="computeroutput"><span class="identifier">_</span></code>"
+ could not be used instead of the letter "<code class="computeroutput"><span class="identifier">X</span></code>"
+ because if the original symbols already contained a leading or trailing
+ underscore, the concatenation could result in a symbol with double underscores
+ "<code class="computeroutput"><span class="identifier">__</span></code>" which is
+ reserved by the C++ standard. The "aux" symbols are private to
+ this library while the "detail" symbols can be used within Boost
+ by other libraries but they are still not part of this library public API.
+ </p></div>
+</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 &#169; 2009-2012 Lorenzo
+ Caminiti<p>
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="../index.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><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="Tutorial.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>

Added: sandbox/closure/libs/local_function/doc/html/boost_localfunction/Implementation.html
==============================================================================
--- (empty file)
+++ sandbox/closure/libs/local_function/doc/html/boost_localfunction/Implementation.html 2012-01-21 13:28:36 EST (Sat, 21 Jan 2012)
@@ -0,0 +1,422 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
+<title>Appendix: Implementation</title>
+<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
+<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;Boost.LocalFunction 1.0.0">
+<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;Boost.LocalFunction 1.0.0">
+<link rel="prev" href="No_Variadic_Macros.html" title="Annex: No Variadic Macros">
+<link rel="next" href="Release_Notes.html" title="Release Notes">
+</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">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="No_Variadic_Macros.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><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="Release_Notes.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_localfunction.Implementation"></a><a class="link" href="Implementation.html" title="Appendix: Implementation">Appendix: Implementation</a>
+</h2></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"><a href="Implementation.html#boost_localfunction.Implementation.local_classes_as_template_parameters">Local
+ Classes as Template Parameters</a></span></dt>
+<dt><span class="section"><a href="Implementation.html#boost_localfunction.Implementation.parsing_macros">Parsing
+ Macros</a></span></dt>
+<dt><span class="section"><a href="Implementation.html#boost_localfunction.Implementation.local_functions">Local
+ Functions</a></span></dt>
+</dl></div>
+<p>
+ This section gives an overview of the key programming techniques used to implement
+ this library.
+ </p>
+<div class="note"><table border="0" summary="Note">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../doc/src/images/note.png"></td>
+<th align="left">Note</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ The code listed here can be used by curious readers and library maintainers
+ as a reference in trying to understand this library source files. There is
+ absolutely no guarantee that the library implementation uses the exact code
+ listed here.
+ </p></td></tr>
+</table></div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Implementation.local_classes_as_template_parameters"></a><a class="link" href="Implementation.html#boost_localfunction.Implementation.local_classes_as_template_parameters" title="Local Classes as Template Parameters">Local
+ Classes as Template Parameters</a>
+</h3></div></div></div>
+<p>
+ This library uses a local class to implement the local function object. However,
+ in C++03
+ local classes (and therefore the local function objects they implement) cannot
+ be passed as template parameters (e.g., to the <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span></code>
+ algorithm), this is instead possible on C++11,
+ MSVC, and some other compilers (see [N2657]).
+ To work around this limitation, this library investigated the following two
+ "tricks" (both tricks can be extended to support eventual function
+ default parameters):
+ </p>
+<div class="orderedlist"><ol class="orderedlist" type="1">
+<li class="listitem">
+ The <span class="emphasis"><em>casting functor trick</em></span> uses a non-local functor
+ that calls a static member function of the local class via a function
+ pointer. The static member function then calls the correct local function
+ body after type casting the object from a <code class="computeroutput"><span class="keyword">void</span><span class="special">*</span></code> pointer (local classes can always be
+ used for type casting).
+ </li>
+<li class="listitem">
+ The <span class="emphasis"><em>virtual functor trick</em></span> derives the local functor
+ class from a non-local base class. The correct overridden implementation
+ of the virtual <code class="computeroutput"><span class="keyword">operator</span><span class="special">()</span></code> is then called via polymorphism.
+ </li>
+</ol></div>
+<p>
+</p>
+<pre class="programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_MODULE</span> <span class="identifier">ExampleTparamTricks</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">vector</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">algorithm</span><span class="special">&gt;</span>
+
+<span class="comment">// Casting functor trick.</span>
+<span class="keyword">struct</span> <span class="identifier">casting_func</span> <span class="special">{</span>
+ <span class="keyword">explicit</span> <span class="identifier">casting_func</span><span class="special">(</span><span class="keyword">void</span><span class="special">*</span> <span class="identifier">obj</span><span class="special">,</span> <span class="keyword">void</span> <span class="special">(*</span><span class="identifier">call</span><span class="special">)(</span><span class="keyword">void</span><span class="special">*,</span> <span class="keyword">const</span> <span class="keyword">int</span><span class="special">&amp;)):</span>
+ <span class="identifier">obj_</span><span class="special">(</span><span class="identifier">obj</span><span class="special">),</span> <span class="identifier">call_</span><span class="special">(</span><span class="identifier">call</span><span class="special">)</span> <span class="special">{}</span>
+ <span class="comment">// Unfortunately, function pointer call is not inlined.</span>
+ <span class="keyword">inline</span> <span class="keyword">void</span> <span class="keyword">operator</span><span class="special">()(</span><span class="keyword">const</span> <span class="keyword">int</span><span class="special">&amp;</span> <span class="identifier">num</span><span class="special">)</span> <span class="special">{</span> <span class="identifier">call_</span><span class="special">(</span><span class="identifier">obj_</span><span class="special">,</span> <span class="identifier">num</span><span class="special">);</span> <span class="special">}</span>
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="keyword">void</span><span class="special">*</span> <span class="identifier">obj_</span><span class="special">;</span>
+ <span class="keyword">void</span> <span class="special">(*</span><span class="identifier">call_</span><span class="special">)(</span><span class="keyword">void</span><span class="special">*,</span> <span class="keyword">const</span> <span class="keyword">int</span><span class="special">&amp;);</span>
+<span class="special">};</span>
+
+<span class="comment">// Virtual functor trick.</span>
+<span class="keyword">struct</span> <span class="identifier">virtual_func</span> <span class="special">{</span>
+ <span class="keyword">struct</span> <span class="identifier">interface</span> <span class="special">{</span>
+ <span class="comment">// Unfortunately, virtual function call is not inlined.</span>
+ <span class="keyword">inline</span> <span class="keyword">virtual</span> <span class="keyword">void</span> <span class="keyword">operator</span><span class="special">()(</span><span class="keyword">const</span> <span class="keyword">int</span><span class="special">&amp;)</span> <span class="special">{}</span>
+ <span class="special">};</span>
+ <span class="keyword">explicit</span> <span class="identifier">virtual_func</span><span class="special">(</span><span class="identifier">interface</span><span class="special">&amp;</span> <span class="identifier">func</span><span class="special">):</span> <span class="identifier">func_</span><span class="special">(&amp;</span><span class="identifier">func</span><span class="special">)</span> <span class="special">{}</span>
+ <span class="keyword">inline</span> <span class="keyword">void</span> <span class="keyword">operator</span><span class="special">()(</span><span class="keyword">const</span> <span class="keyword">int</span><span class="special">&amp;</span> <span class="identifier">num</span><span class="special">)</span> <span class="special">{</span> <span class="special">(*</span><span class="identifier">func_</span><span class="special">)(</span><span class="identifier">num</span><span class="special">);</span> <span class="special">}</span>
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="identifier">interface</span><span class="special">*</span> <span class="identifier">func_</span><span class="special">;</span>
+<span class="special">};</span>
+
+<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span> <span class="identifier">example_tparam_tricks</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">int</span> <span class="identifier">sum</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">factor</span> <span class="special">=</span> <span class="number">10</span><span class="special">;</span>
+
+ <span class="comment">// Local class for local function.</span>
+ <span class="keyword">struct</span> <span class="identifier">local_add</span><span class="special">:</span> <span class="identifier">virtual_func</span><span class="special">::</span><span class="identifier">interface</span> <span class="special">{</span>
+ <span class="keyword">explicit</span> <span class="identifier">local_add</span><span class="special">(</span><span class="keyword">int</span><span class="special">&amp;</span> <span class="identifier">_sum</span><span class="special">,</span> <span class="keyword">const</span> <span class="keyword">int</span><span class="special">&amp;</span> <span class="identifier">_factor</span><span class="special">):</span>
+ <span class="identifier">sum_</span><span class="special">(</span><span class="identifier">_sum</span><span class="special">),</span> <span class="identifier">factor_</span><span class="special">(</span><span class="identifier">_factor</span><span class="special">)</span> <span class="special">{}</span>
+ <span class="keyword">inline</span> <span class="keyword">void</span> <span class="keyword">operator</span><span class="special">()(</span><span class="keyword">const</span> <span class="keyword">int</span><span class="special">&amp;</span> <span class="identifier">num</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">body</span><span class="special">(</span><span class="identifier">sum_</span><span class="special">,</span> <span class="identifier">factor_</span><span class="special">,</span> <span class="identifier">num</span><span class="special">);</span>
+ <span class="special">}</span>
+ <span class="keyword">inline</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">call</span><span class="special">(</span>
+ <span class="keyword">void</span><span class="special">*</span> <span class="identifier">obj</span><span class="special">,</span> <span class="keyword">const</span> <span class="keyword">int</span><span class="special">&amp;</span> <span class="identifier">num</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">local_add</span><span class="special">*</span> <span class="identifier">self</span> <span class="special">=</span> <span class="keyword">static_cast</span><span class="special">&lt;</span><span class="identifier">local_add</span><span class="special">*&gt;(</span><span class="identifier">obj</span><span class="special">);</span>
+ <span class="identifier">self</span><span class="special">-&gt;</span><span class="identifier">body</span><span class="special">(</span><span class="identifier">self</span><span class="special">-&gt;</span><span class="identifier">sum_</span><span class="special">,</span> <span class="identifier">self</span><span class="special">-&gt;</span><span class="identifier">factor_</span><span class="special">,</span> <span class="identifier">num</span><span class="special">);</span>
+ <span class="special">}</span>
+ <span class="keyword">private</span><span class="special">:</span>
+ <span class="keyword">int</span><span class="special">&amp;</span> <span class="identifier">sum_</span><span class="special">;</span>
+ <span class="keyword">const</span> <span class="keyword">int</span><span class="special">&amp;</span> <span class="identifier">factor_</span><span class="special">;</span>
+ <span class="keyword">inline</span> <span class="keyword">void</span> <span class="identifier">body</span><span class="special">(</span><span class="keyword">int</span><span class="special">&amp;</span> <span class="identifier">sum</span><span class="special">,</span> <span class="keyword">const</span> <span class="keyword">int</span><span class="special">&amp;</span> <span class="identifier">factor</span><span class="special">,</span> <span class="keyword">const</span> <span class="keyword">int</span><span class="special">&amp;</span> <span class="identifier">num</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">sum</span> <span class="special">+=</span> <span class="identifier">factor</span> <span class="special">*</span> <span class="identifier">num</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="special">}</span> <span class="identifier">add_local</span><span class="special">(</span><span class="identifier">sum</span><span class="special">,</span> <span class="identifier">factor</span><span class="special">);</span>
+ <span class="identifier">casting_func</span> <span class="identifier">add_casting</span><span class="special">(&amp;</span><span class="identifier">add_local</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">local_add</span><span class="special">::</span><span class="identifier">call</span><span class="special">);</span>
+ <span class="identifier">virtual_func</span> <span class="identifier">add_virtual</span><span class="special">(</span><span class="identifier">add_local</span><span class="special">);</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">v</span><span class="special">(</span><span class="number">10</span><span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">fill</span><span class="special">(</span><span class="identifier">v</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">v</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span> <span class="number">1</span><span class="special">);</span>
+
+<span class="comment">// std::for_each(v.begin(), v.end(), add_local); // Error but OK on C++11.</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">v</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">v</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span> <span class="identifier">add_casting</span><span class="special">);</span> <span class="comment">// OK.</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">v</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">v</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span> <span class="identifier">add_virtual</span><span class="special">);</span> <span class="comment">// OK.</span>
+
+ <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">sum</span> <span class="special">==</span> <span class="number">200</span> <span class="special">);</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+<p>
+ The casting functor trick measured slightly better run-time performances
+ than the virtual functor trick so the current implementation of this library
+ uses the casting functor trick (probably because in addition to the indirect
+ function call, the virtual functor trick also requires accessing the <a href="http://en.wikipedia.org/wiki/Virtual_method_table" target="_top">virtual function
+ table</a>). However, neither one of tricks has been observed to allow
+ for compiler optimizations that inline the local function calls because they
+ rely on one indirect function call (via either a function pointer or a virtual
+ function respectively). Therefore, on compilers that accept local types as
+ template parameters (MSVC, C++11,
+ etc, see [N2657]),
+ this library automatically generates code that passes the local class type
+ directly as template parameter without using neither one of these two tricks
+ in order to take full advantage of compiler optimizations that inline the
+ local function calls.
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Implementation.parsing_macros"></a><a class="link" href="Implementation.html#boost_localfunction.Implementation.parsing_macros" title="Parsing Macros">Parsing
+ Macros</a>
+</h3></div></div></div>
+<p>
+ This library macros can parse the list of specified parameters and detect
+ if any of the bound parameter name matches the token <code class="computeroutput"><span class="identifier">this_</span></code>
+ (to generate special code to bind the object in scope), or if the parameter
+ is bound by <code class="computeroutput"><span class="keyword">const</span></code> (to generate
+ special code to bind by constant), etc. The parameter tokens are inspected
+ using preprocessor metaprogramming, specifically using the macros from <code class="computeroutput"><span class="string">"boost/local_function/detail/preprocessor/keyword/"</span></code>.
+ <sup>[<a name="boost_localfunction.Implementation.parsing_macros.f0" href="#ftn.boost_localfunction.Implementation.parsing_macros.f0" class="footnote">24</a>]</sup>
+ </p>
+<p>
+ For example, the following code defines a macro that allows the preprocessor
+ to detect if a set of space-separated tokens end with <code class="computeroutput"><span class="identifier">this_</span></code>
+ or not:
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">local_function</span><span class="special">/</span><span class="identifier">detail</span><span class="special">/</span><span class="identifier">preprocessor</span><span class="special">/</span><span class="identifier">keyword</span><span class="special">/</span><span class="identifier">thisunderscore</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">local_function</span><span class="special">/</span><span class="identifier">detail</span><span class="special">/</span><span class="identifier">preprocessor</span><span class="special">/</span><span class="identifier">keyword</span><span class="special">/</span><span class="keyword">const</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">local_function</span><span class="special">/</span><span class="identifier">detail</span><span class="special">/</span><span class="identifier">preprocessor</span><span class="special">/</span><span class="identifier">keyword</span><span class="special">/</span><span class="identifier">bind</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#define</span> <span class="identifier">BOOST_TEST_MODULE</span> <span class="identifier">ExampleImplPpKeyword</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">test</span><span class="special">/</span><span class="identifier">unit_test</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="comment">// Expand to 1 if space-separated tokens end with `this_`, 0 otherwise.</span>
+<span class="preprocessor">#define</span> <span class="identifier">HAS_THIS_</span><span class="special">(</span><span class="identifier">tokens</span><span class="special">)</span> <span class="special">\</span>
+ <span class="identifier">BOOST_LOCAL_FUNCTION_DETAIL_PP_KEYWORD_IS_THISUNDERSCORE_BACK</span><span class="special">(</span> <span class="special">\</span>
+ <span class="identifier">BOOST_LOCAL_FUNCTION_DETAIL_PP_KEYWORD_BIND_REMOVE_FRONT</span><span class="special">(</span> <span class="special">\</span>
+ <span class="identifier">BOOST_LOCAL_FUNCTION_DETAIL_PP_KEYWORD_CONST_REMOVE_FRONT</span><span class="special">(</span> <span class="special">\</span>
+ <span class="identifier">tokens</span> <span class="special">\</span>
+ <span class="special">)))</span>
+
+<span class="identifier">BOOST_AUTO_TEST_CASE</span><span class="special">(</span> <span class="identifier">example_impl_pp_keyword</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">HAS_THIS_</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">bind</span> <span class="identifier">this_</span><span class="special">)</span> <span class="special">==</span> <span class="number">1</span> <span class="special">);</span>
+ <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">HAS_THIS_</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">bind</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">==</span> <span class="number">0</span> <span class="special">);</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Implementation.local_functions"></a><a class="link" href="Implementation.html#boost_localfunction.Implementation.local_functions" title="Local Functions">Local
+ Functions</a>
+</h3></div></div></div>
+<p>
+ The local function macros expand to code equivalent to the following:
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">local</span><span class="special">/</span><span class="identifier">function</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">iostream</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">sstream</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">algorithm</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">vector</span><span class="special">&gt;</span>
+<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">string</span><span class="special">&gt;</span>
+
+<span class="keyword">struct</span> <span class="identifier">calculator</span> <span class="special">{</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">ostringstream</span> <span class="identifier">output</span><span class="special">;</span>
+
+ <span class="keyword">void</span> <span class="identifier">factorials</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;&amp;</span> <span class="identifier">nums</span><span class="special">,</span>
+ <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">&amp;</span> <span class="identifier">separator</span> <span class="special">=</span> <span class="string">" "</span><span class="special">)</span> <span class="special">{</span>
+
+ <span class="keyword">int</span> <span class="comment">// The local function result type (just before the `BOOST_LOCAL_FUNCTION_PARAMS` macro).</span>
+
+ <span class="comment">// *BEGIN* The macro</span>
+ <span class="comment">// BOOST_LOCAL_FUNCTION_PARAMS( (int n) (bool recursion)(default false)</span>
+ <span class="comment">// (const bind&amp; separator) (bind this) )</span>
+ <span class="comment">// expands (at line 21) to:</span>
+
+ <span class="comment">// DEDUCE RESULT TYPE</span>
+ <span class="comment">// Long name `ERROR_...` gives meaningful compiler-error message if programmers forget result type before the macro. </span>
+ <span class="special">(*</span><span class="identifier">ERROR_missing_result_type_before_the_local_function_parameter_macro_id21</span><span class="special">)();</span>
+ <span class="comment">// Use Boost.ScopeExit type deduction technique (tagging, wrapping, struct, etc) so to work on all compilers (specifically, some GCC version give internal errors otherwise).</span>
+ <span class="keyword">typedef</span> <span class="keyword">void</span> <span class="special">(*</span><span class="identifier">boost_local_auxXdeduce_result_tag21</span><span class="special">)(</span> <span class="keyword">int</span> <span class="identifier">ERROR_missing_result_type_before_the_local_function_parameter_macro_id21</span><span class="special">);</span>
+ <span class="keyword">typedef</span> <span class="identifier">BOOST_TYPEOF</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">scope_exit</span><span class="special">::</span><span class="identifier">aux</span><span class="special">::</span><span class="identifier">wrap</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">scope_exit</span><span class="special">::</span><span class="identifier">aux</span><span class="special">::</span><span class="identifier">deref</span><span class="special">(</span> <span class="identifier">ERROR_missing_result_type_before_the_local_function_parameter_macro_id21</span><span class="special">,</span> <span class="special">(</span><span class="identifier">boost_local_auxXdeduce_result_tag21</span><span class="special">)</span><span class="number">0</span><span class="special">)))</span> <span class="identifier">boost
_local_auxXdeduce_result_wrap21</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">boost_local_auxXdeduce_result_wrap21</span><span class="special">::</span><span class="identifier">type</span> <span class="identifier">boost_local_auxXdeduce_result_capture21</span><span class="special">;</span>
+ <span class="keyword">struct</span> <span class="identifier">boost_local_auxXdeduce_result_params21</span> <span class="special">{</span>
+ <span class="keyword">typedef</span> <span class="identifier">boost_local_auxXdeduce_result_capture21</span> <span class="identifier">function_ptr_type</span><span class="special">;</span>
+ <span class="special">};</span>
+ <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">remove_pointer</span><span class="special">&lt;</span> <span class="identifier">boost_local_auxXdeduce_result_params21</span><span class="special">::</span><span class="identifier">function_ptr_type</span> <span class="special">&gt;::</span><span class="identifier">type</span> <span class="identifier">boost_local_auxXdeduce_result_function_type21</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special">&lt;</span> <span class="identifier">boost_local_auxXdeduce_result_function_type21</span><span class="special">&gt;::</span><span class="identifier">result_type</span> <span class="identifier">boost_local_auxXresult_type21</span><span class="special">;</span>
+
+ <span class="comment">// HANDLE BOUND PARAMETERS</span>
+ <span class="comment">// Deduce object `this` type (using technique from Boost.ScopeExit patch to support `this`).</span>
+<span class="preprocessor">#if</span> <span class="identifier">BOOST_WORKAROUND</span><span class="special">(</span><span class="identifier">BOOST_MSVC</span><span class="special">,&gt;=</span><span class="number">1300</span><span class="special">)</span>
+ <span class="keyword">enum</span> <span class="special">{</span> <span class="identifier">boost_se_thistype_index_21</span> <span class="special">=</span> <span class="keyword">sizeof</span><span class="special">(*</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">scope_exit</span><span class="special">::</span><span class="identifier">msvc_typeof_this</span><span class="special">::</span><span class="identifier">encode_start</span><span class="special">(</span><span class="keyword">this</span><span class="special">))</span> <span class="special">};</span>
+ <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">scope_exit</span><span class="special">::</span><span class="identifier">msvc_typeof_this</span><span class="special">::</span><span class="identifier">msvc_typeid_wrapper</span><span class="special">&lt;</span><span class="identifier">boost_se_thistype_index_21</span><span class="special">&gt;::</span><span class="identifier">type</span> <span class="identifier">se_this_type21</span><span class="special">;</span>
+<span class="preprocessor">#else</span>
+ <span class="keyword">typedef</span> <span class="identifier">BOOST_TYPEOF</span><span class="special">(</span><span class="keyword">this</span><span class="special">)</span> <span class="identifier">se_this_type21</span><span class="special">;</span>
+<span class="preprocessor">#endif</span>
+ <span class="comment">// Deduce other `&amp; separator` type (using Boost.ScopeExit techniques).</span>
+ <span class="keyword">typedef</span> <span class="keyword">void</span> <span class="special">(*</span><span class="identifier">boost_se_tag_0_21</span><span class="special">)(</span><span class="keyword">int</span> <span class="special">&amp;</span> <span class="identifier">separator</span><span class="special">);</span>
+ <span class="keyword">typedef</span> <span class="identifier">BOOST_TYPEOF</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">scope_exit</span><span class="special">::</span><span class="identifier">aux</span><span class="special">::</span><span class="identifier">wrap</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">scope_exit</span><span class="special">::</span><span class="identifier">aux</span><span class="special">::</span><span class="identifier">deref</span><span class="special">(&amp;</span> <span class="identifier">separator</span><span class="special">,</span> <span class="special">(</span><span class="identifier">boost_se_tag_0_21</span><span class="special">)</span><span class="number">0</span><span class="special">)))</span> <span class="identifier">boost_se_wrapped_t_0_21</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">boost_se_wrapped_t_0_21</span><span class="special">::</span><span class="identifier">type</span> <span class="identifier">boost_se_capture_t_0_21</span><span class="special">;</span>
+ <span class="comment">// Store bound parameter values and references.</span>
+ <span class="keyword">struct</span> <span class="identifier">boost_se_params_t_21</span> <span class="special">{</span>
+ <span class="identifier">se_this_type21</span> <span class="identifier">se_this</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">boost_se_capture_t_0_21</span> <span class="identifier">boost_se_param_t_0_21</span><span class="special">;</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">scope_exit</span><span class="special">::</span><span class="identifier">aux</span><span class="special">::</span><span class="identifier">member</span><span class="special">&lt;</span> <span class="identifier">boost_se_param_t_0_21</span><span class="special">,</span> <span class="identifier">boost_se_tag_0_21</span> <span class="special">&gt;</span> <span class="identifier">boost_se_param_0_21</span><span class="special">;</span>
+ <span class="special">}</span> <span class="identifier">boost_local_auxXparams21</span> <span class="special">=</span> <span class="special">{</span>
+ <span class="keyword">this</span> <span class="special">,</span>
+<span class="preprocessor">#ifdef</span> <span class="identifier">BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND</span>
+ <span class="special">{</span>
+<span class="preprocessor">#endif</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">scope_exit</span><span class="special">::</span><span class="identifier">aux</span><span class="special">::</span><span class="identifier">deref</span><span class="special">(&amp;</span> <span class="identifier">separator</span><span class="special">,</span> <span class="special">(</span><span class="identifier">boost_se_tag_0_21</span><span class="special">)</span><span class="number">0</span><span class="special">)</span>
+<span class="preprocessor">#ifdef</span> <span class="identifier">BOOST_SCOPE_EXIT_AUX_TPL_WORKAROUND</span>
+ <span class="special">}</span>
+<span class="preprocessor">#endif</span>
+ <span class="special">};</span>
+ <span class="comment">// Use variable name `...args` without line number to hold bound parameter values (so the same variable name can be used by the `NAME` macro even if it expands on a different line number).</span>
+ <span class="comment">// The `declared&lt;&gt;` template makes sure that the variable `...args` is not declared multiple times in the same context (if the variable is already declared, this template expand to a no-operation).</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">scope_exit</span><span class="special">::</span><span class="identifier">aux</span><span class="special">::</span><span class="identifier">declared</span><span class="special">&lt;</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">scope_exit</span><span class="special">::</span><span class="identifier">aux</span><span class="special">::</span><span class="identifier">resolve</span><span class="special">&lt;</span> <span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">boost_local_auxXargs</span><span class="special">)</span> <span class="special">&gt;::</span><span class="identifier">cmp1</span><span class="special">&lt;</span><span class="number">0</span><span class="special">&gt;::</span><span class="identifier">cmp2</span> <span class="special">&gt;</span> <span class="identifier">boost_local_auxXargs</span><span class="s
pecial">;</span>
+ <span class="identifier">boost_local_auxXargs</span><span class="special">.</span><span class="identifier">value</span> <span class="special">=</span> <span class="special">&amp;</span><span class="identifier">boost_local_auxXparams21</span><span class="special">;</span>
+
+ <span class="comment">// LOCAL FUNCTOR</span>
+ <span class="keyword">class</span> <span class="identifier">boost_local_auxXfunctor21</span> <span class="special">{</span>
+ <span class="keyword">typedef</span> <span class="identifier">boost_local_auxXresult_type21</span> <span class="special">(</span><span class="identifier">boost_local_auxXfunction_type</span><span class="special">)</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">n</span> <span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">recursion</span> <span class="special">);</span>
+ <span class="keyword">typedef</span> <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">local</span><span class="special">::</span><span class="identifier">aux</span><span class="special">::</span><span class="identifier">function</span><span class="special">&lt;</span> <span class="identifier">boost_local_auxXfunction_type</span><span class="special">,</span> <span class="number">1</span> <span class="special">&gt;</span> <span class="identifier">boost_local_auxXfunctor_type</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">add_const</span><span class="special">&lt;</span> <span class="identifier">boost_se_params_t_21</span><span class="special">::</span> <span class="identifier">boost_se_param_t_0_21</span> <span class="special">&gt;::</span><span class="identifier">type</span> <span class="special">&amp;</span> <span class="identifier">separatorXboost_local_auxXtypeof_type</span> <span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">se_this_type21</span> <span class="identifier">thisXboost_local_auxXtypeof_type</span> <span class="special">;</span>
+ <span class="keyword">public</span><span class="special">:</span>
+ <span class="comment">// Take a generic pointer so it can be invoked by the `NAME` macro even if it expands on a different line number. </span>
+ <span class="keyword">inline</span> <span class="keyword">explicit</span> <span class="identifier">boost_local_auxXfunctor21</span><span class="special">(</span> <span class="keyword">void</span><span class="special">*</span> <span class="identifier">bindings</span><span class="special">)</span> <span class="special">:</span>
+ <span class="identifier">boost_local_auxXbind_this</span><span class="special">(</span> <span class="keyword">static_cast</span><span class="special">&lt;</span> <span class="identifier">boost_se_params_t_21</span><span class="special">*</span> <span class="special">&gt;(</span> <span class="identifier">bindings</span><span class="special">)-&gt;</span> <span class="identifier">se_this</span> <span class="special">)</span>
+ <span class="special">,</span> <span class="identifier">boost_local_auxXbind0</span> <span class="special">(</span> <span class="keyword">static_cast</span><span class="special">&lt;</span> <span class="identifier">boost_se_params_t_21</span><span class="special">*</span> <span class="special">&gt;(</span> <span class="identifier">bindings</span><span class="special">)-&gt;</span> <span class="identifier">boost_se_param_0_21</span><span class="special">.</span><span class="identifier">value</span> <span class="special">)</span>
+ <span class="special">{</span> <span class="special">}</span>
+
+ <span class="comment">// Implement `operator()` for all parameters and any combination of default parameter.</span>
+ <span class="keyword">inline</span> <span class="identifier">boost_local_auxXresult_type21</span> <span class="keyword">operator</span><span class="special">()(</span>
+ <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">call_traits</span><span class="special">&lt;</span> <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special">&lt;</span> <span class="identifier">boost_local_auxXfunction_type</span><span class="special">&gt;::</span><span class="identifier">arg1_type</span><span class="special">&gt;::</span><span class="identifier">param_type</span> <span class="identifier">arg1</span>
+ <span class="special">,</span> <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">call_traits</span><span class="special">&lt;</span> <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special">&lt;</span> <span class="identifier">boost_local_auxXfunction_type</span><span class="special">&gt;::</span><span class="identifier">arg2_type</span><span class="special">&gt;::</span><span class="identifier">param_type</span> <span class="identifier">arg2</span>
+ <span class="special">)</span> <span class="keyword">const</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">boost_local_auxXbody</span><span class="special">(</span> <span class="identifier">boost_local_auxXbind0</span> <span class="special">,</span> <span class="identifier">boost_local_auxXbind_this</span> <span class="special">,</span> <span class="identifier">arg1</span> <span class="special">,</span> <span class="identifier">arg2</span> <span class="special">);</span>
+ <span class="special">}</span>
+ <span class="keyword">inline</span> <span class="identifier">boost_local_auxXresult_type21</span> <span class="keyword">operator</span><span class="special">()(</span>
+ <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">call_traits</span><span class="special">&lt;</span> <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special">&lt;</span> <span class="identifier">boost_local_auxXfunction_type</span><span class="special">&gt;::</span><span class="identifier">arg1_type</span><span class="special">&gt;::</span><span class="identifier">param_type</span> <span class="identifier">arg1</span>
+ <span class="special">)</span> <span class="keyword">const</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">boost_local_auxXbody</span><span class="special">(</span> <span class="identifier">boost_local_auxXbind0</span> <span class="special">,</span> <span class="identifier">boost_local_auxXbind_this</span> <span class="special">,</span> <span class="identifier">arg1</span> <span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="comment">// "Casting functor trick" to pass this local class as template parameter.</span>
+ <span class="keyword">inline</span> <span class="keyword">static</span> <span class="identifier">boost_local_auxXresult_type21</span> <span class="identifier">boost_local_auxXcall0</span><span class="special">(</span>
+ <span class="keyword">void</span><span class="special">*</span> <span class="identifier">object</span>
+ <span class="special">,</span> <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">call_traits</span><span class="special">&lt;</span> <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special">&lt;</span> <span class="identifier">boost_local_auxXfunction_type</span><span class="special">&gt;::</span><span class="identifier">arg1_type</span><span class="special">&gt;::</span><span class="identifier">param_type</span> <span class="identifier">arg1</span>
+ <span class="special">,</span> <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">call_traits</span><span class="special">&lt;</span> <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special">&lt;</span> <span class="identifier">boost_local_auxXfunction_type</span><span class="special">&gt;::</span><span class="identifier">arg2_type</span><span class="special">&gt;::</span><span class="identifier">param_type</span> <span class="identifier">arg2</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="keyword">static_cast</span><span class="special">&lt;</span> <span class="identifier">boost_local_auxXfunctor21</span><span class="special">*</span> <span class="special">&gt;(</span> <span class="identifier">object</span><span class="special">)-&gt;</span><span class="keyword">operator</span><span class="special">()(</span> <span class="identifier">arg1</span> <span class="special">,</span> <span class="identifier">arg2</span> <span class="special">);</span>
+ <span class="special">}</span>
+ <span class="keyword">inline</span> <span class="keyword">static</span> <span class="identifier">boost_local_auxXresult_type21</span> <span class="identifier">boost_local_auxXcall1</span><span class="special">(</span>
+ <span class="keyword">void</span><span class="special">*</span> <span class="identifier">object</span>
+ <span class="special">,</span> <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">call_traits</span><span class="special">&lt;</span> <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">function_traits</span><span class="special">&lt;</span> <span class="identifier">boost_local_auxXfunction_type</span><span class="special">&gt;::</span><span class="identifier">arg1_type</span><span class="special">&gt;::</span><span class="identifier">param_type</span> <span class="identifier">arg1</span>
+ <span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="keyword">static_cast</span><span class="special">&lt;</span> <span class="identifier">boost_local_auxXfunctor21</span><span class="special">*</span> <span class="special">&gt;(</span> <span class="identifier">object</span><span class="special">)-&gt;</span><span class="keyword">operator</span><span class="special">()(</span> <span class="identifier">arg1</span> <span class="special">);</span>
+ <span class="special">}</span>
+ <span class="keyword">inline</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">boost_local_auxXinit_call</span><span class="special">(</span> <span class="keyword">void</span><span class="special">*</span> <span class="identifier">object</span><span class="special">,</span> <span class="identifier">boost_local_auxXfunctor_type</span><span class="special">&amp;</span> <span class="identifier">functor</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">functor</span><span class="special">.</span><span class="identifier">boost_local_auxXinit_call</span><span class="special">(</span><span class="identifier">object</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">boost_local_auxXcall0</span> <span class="special">,</span> <span class="special">&amp;</span><span class="identifier">boost_local_auxXcall1</span> <span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="keyword">private</span><span class="special">:</span>
+ <span class="comment">// Hold bound variables (by value and reference).</span>
+ <span class="identifier">se_this_type21</span> <span class="special">&amp;</span> <span class="identifier">boost_local_auxXbind_this</span> <span class="special">;</span>
+ <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">add_const</span><span class="special">&lt;</span> <span class="identifier">boost_se_params_t_21</span><span class="special">::</span> <span class="identifier">boost_se_param_t_0_21</span> <span class="special">&gt;::</span><span class="identifier">type</span> <span class="special">&amp;</span> <span class="identifier">boost_local_auxXbind0</span> <span class="special">;</span>
+ <span class="comment">// This same declaration is first made at global scope in one of the library header files. This declaration needs to be repeated here so it is also visible from within the local function body to allow for nesting local function into one another.</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">scope_exit</span><span class="special">::</span><span class="identifier">aux</span><span class="special">::</span><span class="identifier">undeclared</span> <span class="identifier">boost_local_auxXargs</span><span class="special">;</span>
+
+ <span class="comment">// The local function body.</span>
+ <span class="keyword">inline</span> <span class="identifier">boost_local_auxXresult_type21</span> <span class="identifier">boost_local_auxXbody</span><span class="special">(</span>
+ <span class="special">::</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">add_const</span><span class="special">&lt;</span> <span class="identifier">boost_se_params_t_21</span><span class="special">::</span> <span class="identifier">boost_se_param_t_0_21</span> <span class="special">&gt;::</span><span class="identifier">type</span> <span class="special">&amp;</span> <span class="identifier">separator</span>
+ <span class="special">,</span> <span class="identifier">se_this_type21</span> <span class="keyword">const</span> <span class="identifier">this_</span> <span class="comment">// Use special name `this_` instead of `this` here.</span>
+ <span class="comment">// Specify default parameter values here.</span>
+ <span class="special">,</span> <span class="keyword">int</span> <span class="identifier">n</span> <span class="special">,</span> <span class="keyword">bool</span> <span class="identifier">recursion</span> <span class="special">=</span> <span class="keyword">false</span>
+ <span class="special">)</span> <span class="keyword">const</span>
+
+ <span class="comment">// *END* The expansion of `BOOST_LOCAL_FUNCTION_PARAMS` ends here.</span>
+
+ <span class="comment">// *BEGIN* The local function body code `{ ... }` as specified by the programmers:</span>
+
+ <span class="special">{</span>
+
+ <span class="keyword">int</span> <span class="identifier">result</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+
+ <span class="keyword">if</span> <span class="special">(</span><span class="identifier">n</span> <span class="special">&lt;</span> <span class="number">2</span> <span class="special">)</span> <span class="identifier">result</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span>
+ <span class="keyword">else</span> <span class="identifier">result</span> <span class="special">=</span> <span class="identifier">n</span> <span class="special">*</span> <span class="identifier">factorial</span><span class="special">(</span><span class="identifier">n</span> <span class="special">-</span> <span class="number">1</span><span class="special">,</span> <span class="keyword">true</span><span class="special">);</span> <span class="comment">// Recursive call.</span>
+
+ <span class="keyword">if</span> <span class="special">(!</span><span class="identifier">recursion</span><span class="special">)</span> <span class="identifier">this_</span><span class="special">-&gt;</span><span class="identifier">output</span> <span class="special">&lt;&lt;</span> <span class="identifier">result</span> <span class="special">&lt;&lt;</span> <span class="identifier">separator</span><span class="special">;</span>
+ <span class="keyword">return</span> <span class="identifier">result</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="comment">// *END* The local function body `{ ... }` ends here.</span>
+
+ <span class="comment">// *BEGIN* The macro `BOOST_LOCAL_FUNCTION_NAME(recursive factorial)` expands to:</span>
+
+ <span class="keyword">public</span><span class="special">:</span>
+ <span class="comment">// Member variable named after the local function so the body can recursively call the local function (this must be defined here because the local function name was not known before). This must be public because it is also used to deduce the local function functor type later when when declaring the actual local function object.</span>
+ <span class="identifier">boost_local_auxXfunctor_type</span> <span class="identifier">factorial</span><span class="special">;</span>
+ <span class="comment">// Initializes the local functor member variable (this cannot be done directly within the constructor because the local function name is not known when the constructor code is expanded by the `PARAMS` macro).</span>
+ <span class="keyword">inline</span> <span class="keyword">void</span> <span class="identifier">boost_local_auxXinit_recursion</span><span class="special">(</span> <span class="identifier">boost_local_auxXfunctor_type</span><span class="special">&amp;</span> <span class="identifier">functor</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">factorial</span> <span class="special">=</span> <span class="identifier">functor</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="comment">// Declare the local class object -- which cannot be passed as template parameter (because it is a local class). It uses the variable with the generic `...args` name to pass the bound parameter values and references (so this variable name must not contain the line number because it is used by different macros expanding on different lines).</span>
+ <span class="special">}</span> <span class="identifier">boost_local_auxXfactorial</span><span class="special">(</span><span class="identifier">boost_local_auxXargs</span><span class="special">.</span><span class="identifier">value</span><span class="special">);</span>
+ <span class="comment">// Declare the actual local function object with the local function name -- which can be passed as template parameter (because it is a `boost::local::function` functor and not a local class).</span>
+ <span class="identifier">BOOST_TYPEOF</span><span class="special">(</span><span class="identifier">boost_local_auxXfactorial</span><span class="special">.</span> <span class="identifier">factorial</span><span class="special">)</span> <span class="identifier">factorial</span><span class="special">;</span>
+ <span class="comment">// Initializes casting functor to pass local function as template parameter.</span>
+ <span class="identifier">boost_local_auxXfactorial</span><span class="special">.</span><span class="identifier">boost_local_auxXinit_call</span><span class="special">(</span> <span class="special">&amp;</span><span class="identifier">boost_local_auxXfactorial</span><span class="special">,</span> <span class="identifier">factorial</span><span class="special">);</span>
+ <span class="comment">// Initializes functor for recursion.</span>
+ <span class="identifier">boost_local_auxXfactorial</span><span class="special">.</span><span class="identifier">boost_local_auxXinit_recursion</span><span class="special">(</span> <span class="identifier">factorial</span><span class="special">);</span>
+
+ <span class="comment">// *END* The expansion of `BOOST_LOCAL_FUNCTION_NAME` ends here.</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">nums</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">nums</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span> <span class="identifier">factorial</span><span class="special">);</span>
+ <span class="special">}</span>
+<span class="special">};</span>
+
+<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span> <span class="special">{</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;</span> <span class="identifier">v</span><span class="special">(</span><span class="number">3</span><span class="special">);</span>
+ <span class="identifier">v</span><span class="special">[</span><span class="number">0</span><span class="special">]</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span> <span class="identifier">v</span><span class="special">[</span><span class="number">1</span><span class="special">]</span> <span class="special">=</span> <span class="number">4</span><span class="special">;</span> <span class="identifier">v</span><span class="special">[</span><span class="number">2</span><span class="special">]</span> <span class="special">=</span> <span class="number">7</span><span class="special">;</span>
+
+ <span class="identifier">calculator</span> <span class="identifier">calc</span><span class="special">;</span>
+ <span class="identifier">calc</span><span class="special">.</span><span class="identifier">factorials</span><span class="special">(</span><span class="identifier">v</span><span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">calc</span><span class="special">.</span><span class="identifier">output</span><span class="special">.</span><span class="identifier">str</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="footnotes">
+<br><hr width="100" align="left">
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Implementation.parsing_macros.f0" href="#boost_localfunction.Implementation.parsing_macros.f0" class="para">24</a>] </sup>
+ This technique is at the core of even more complex preprocessor parsing
+ macros like the ones that parse the Contract++
+ syntax.
+ </p></div>
+</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 &#169; 2009-2012 Lorenzo
+ Caminiti<p>
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="No_Variadic_Macros.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><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="Release_Notes.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>

Added: sandbox/closure/libs/local_function/doc/html/boost_localfunction/No_Variadic_Macros.html
==============================================================================
--- (empty file)
+++ sandbox/closure/libs/local_function/doc/html/boost_localfunction/No_Variadic_Macros.html 2012-01-21 13:28:36 EST (Sat, 21 Jan 2012)
@@ -0,0 +1,232 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
+<title>Annex: No Variadic Macros</title>
+<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
+<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;Boost.LocalFunction 1.0.0">
+<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;Boost.LocalFunction 1.0.0">
+<link rel="prev" href="Alternatives.html" title="Appendix: Alternatives">
+<link rel="next" href="Implementation.html" title="Appendix: Implementation">
+</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">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="Alternatives.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><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="Implementation.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_localfunction.No_Variadic_Macros"></a><a class="link" href="No_Variadic_Macros.html" title="Annex: No Variadic Macros">Annex: No Variadic
+ Macros</a>
+</h2></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"><a href="No_Variadic_Macros.html#boost_localfunction.No_Variadic_Macros.sequence_syntax">Sequence
+ Syntax</a></span></dt>
+<dt><span class="section">Examples</span></dt>
+</dl></div>
+<p>
+ This section illustrates an alternative syntax for compilers without variadic
+ macro support.
+ </p>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.No_Variadic_Macros.sequence_syntax"></a><a class="link" href="No_Variadic_Macros.html#boost_localfunction.No_Variadic_Macros.sequence_syntax" title="Sequence Syntax">Sequence
+ Syntax</a>
+</h3></div></div></div>
+<p>
+ Most modern compilers support <a href="http://en.wikipedia.org/wiki/Variadic_macro" target="_top">variaid
+ macros</a> (notably, these include GCC, MSVC, and all C++11
+ compilers). However, in the rare case that programmers need to use this library
+ on a compiler without variadic macros, this library also allows to specify
+ its macro parameters using a Boost.Preprocessor
+ sequence where tokens are separated by round parenthesis <code class="computeroutput"><span class="special">()</span></code>:
+ </p>
+<pre class="programlisting"><span class="special">(</span><span class="identifier">token1</span><span class="special">)</span> <span class="special">(</span><span class="identifier">token2</span><span class="special">)</span> <span class="special">...</span> <span class="comment">// All compilers.</span>
+</pre>
+<p>
+ Instead of the comma-separated list that we have seen so far which requires
+ variadic macros:
+ </p>
+<pre class="programlisting"><span class="identifier">token1</span><span class="special">,</span> <span class="identifier">token2</span><span class="special">,</span> <span class="special">...</span> <span class="comment">// Only compilers with varidic macros.</span>
+</pre>
+<p>
+ For example, the following syntax is accepted on all compilers with and without
+ variadic macros (see also "add_seq.cpp"):
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">sum</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">factor</span> <span class="special">=</span> <span class="number">10</span><span class="special">;</span> <span class="comment">// Variables in scope to bind.</span>
+
+<span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span> <span class="special">(</span><span class="keyword">const</span> <span class="identifier">bind</span> <span class="identifier">factor</span><span class="special">)</span> <span class="special">(</span><span class="identifier">bind</span><span class="special">&amp;</span> <span class="identifier">sum</span><span class="special">)</span> <span class="special">(</span><span class="keyword">int</span> <span class="identifier">num</span><span class="special">)</span> <span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">sum</span> <span class="special">+=</span> <span class="identifier">factor</span> <span class="special">*</span> <span class="identifier">num</span><span class="special">;</span>
+<span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">add</span><span class="special">)</span>
+
+<span class="identifier">add</span><span class="special">(</span><span class="number">1</span><span class="special">);</span> <span class="comment">// Call the local function (with one parameter `num`).</span>
+
+<span class="keyword">int</span> <span class="identifier">nums</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span><span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">};</span>
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">nums</span><span class="special">,</span> <span class="identifier">nums</span> <span class="special">+</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">add</span><span class="special">);</span> <span class="comment">// Pass it to an algorithm.</span>
+</pre>
+<p>
+ </p>
+<p>
+ However, on compilers with variadic macros the comma-separated syntax we
+ have seen so far is preferred because more readable (see also "add.cpp"):
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="special">{</span> <span class="comment">// Some local scope.</span>
+ <span class="keyword">int</span> <span class="identifier">sum</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">factor</span> <span class="special">=</span> <span class="number">10</span><span class="special">;</span> <span class="comment">// Variables in scope to bind.</span>
+
+ <span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">bind</span> <span class="identifier">factor</span><span class="special">,</span> <span class="identifier">bind</span><span class="special">&amp;</span> <span class="identifier">sum</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">num</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">sum</span> <span class="special">+=</span> <span class="identifier">factor</span> <span class="special">*</span> <span class="identifier">num</span><span class="special">;</span>
+ <span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">add</span><span class="special">)</span>
+
+ <span class="identifier">add</span><span class="special">(</span><span class="number">1</span><span class="special">);</span> <span class="comment">// Call the local function (with one parameter `num`).</span>
+ <span class="keyword">int</span> <span class="identifier">nums</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span><span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">};</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">nums</span><span class="special">,</span> <span class="identifier">nums</span> <span class="special">+</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">add</span><span class="special">);</span> <span class="comment">// Pass it to an algorithm.</span>
+
+ <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">sum</span> <span class="special">==</span> <span class="number">60</span> <span class="special">);</span> <span class="comment">// Assert final summation value.</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+<p>
+ Note how the same macros accept both syntaxes on compilers with variadic
+ macros and only the sequence syntax on compilers without variadic macros.
+ Finally, an empty list is always specified using <code class="computeroutput"><span class="keyword">void</span></code>
+ on compilers with and without variadic macros.
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.No_Variadic_Macros.examples"></a><a class="link" href="No_Variadic_Macros.html#boost_localfunction.No_Variadic_Macros.examples" title="Examples">Examples</a>
+</h3></div></div></div>
+<p>
+ The following is a list of most of the examples presented in this documentation
+ reprogrammed using the sequence syntax instead of the comma-separated list:
+ </p>
+<div class="informaltable"><table class="table">
+<colgroup><col></colgroup>
+<thead><tr><th>
+ <p>
+ Files
+ </p>
+ </th></tr></thead>
+<tbody>
+<tr><td>
+ <p>
+ "add_seq.cpp"
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ "add_classifiers_seq.cpp"
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ "add_default_seq.cpp"
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ "add_except_seq.cpp"
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ "add_inline_seq.cpp"
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ "add_lambda_seq.cpp"
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ "add_nobind_seq.cpp"
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ "add_template_seq.cpp"
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ "add_this_seq.cpp"
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ "add_typed_seq.cpp"
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ "add_with_default_seq.cpp"
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ "nesting_seq.cpp"
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ "overload_seq.cpp"
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ "return_assign_seq.cpp"
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ "ten_seq.cpp"
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ "transform_seq.cpp"
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ "typeof_seq.cpp"
+ </p>
+ </td></tr>
+<tr><td>
+ <p>
+ "typeof_template_seq.cpp"
+ </p>
+ </td></tr>
+</tbody>
+</table></div>
+</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 &#169; 2009-2012 Lorenzo
+ Caminiti<p>
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="Alternatives.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><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="Implementation.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>

Added: sandbox/closure/libs/local_function/doc/html/boost_localfunction/Release_Notes.html
==============================================================================
--- (empty file)
+++ sandbox/closure/libs/local_function/doc/html/boost_localfunction/Release_Notes.html 2012-01-21 13:28:36 EST (Sat, 21 Jan 2012)
@@ -0,0 +1,121 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
+<title>Release Notes</title>
+<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
+<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;Boost.LocalFunction 1.0.0">
+<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;Boost.LocalFunction 1.0.0">
+<link rel="prev" href="Implementation.html" title="Appendix: Implementation">
+<link rel="next" href="Bibliography.html" title="Bibliography">
+</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">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="Implementation.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><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="Bibliography.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_localfunction.Release_Notes"></a><a class="link" href="Release_Notes.html" title="Release Notes">Release Notes</a>
+</h2></div></div></div>
+<p>
+ This section lists the major changes between different library releases (in
+ chronological order).
+ </p>
+<h6>
+<a name="boost_localfunction.Release_Notes.h0"></a>
+ <span><a name="boost_localfunction.Release_Notes.version_0_2_0__2011_05_14_"></a></span><a class="link" href="Release_Notes.html#boost_localfunction.Release_Notes.version_0_2_0__2011_05_14_">Version
+ 0.2.0 (2011-05-14)</a>
+ </h6>
+<div class="orderedlist"><ol class="orderedlist" type="1">
+<li class="listitem">
+ Replaced parenthesized syntax with variadic and sequencing macro syntaxes.
+ </li>
+<li class="listitem">
+ Profiled library performances against other approaches.
+ </li>
+<li class="listitem">
+ Replaced virtual functor trick with casting functor trick (for smaller
+ run-time).
+ </li>
+<li class="listitem">
+ Optimized library run-time (rearranging code and not using casting functor
+ trick on compilers that accept local classes as template parameters).
+ </li>
+<li class="listitem">
+ Supported inline and recursive local functions.
+ </li>
+<li class="listitem">
+ Added type-of macro to expose bound types.
+ </li>
+<li class="listitem">
+ Allowed to explicitly specify bound types.
+ </li>
+<li class="listitem">
+ Removed using <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">function</span></code> instead of exposing internal
+ local functor as public API.
+ </li>
+<li class="listitem">
+ Added functor to overload local functions (and functors in general).
+ </li>
+<li class="listitem">
+ Implemented support for nesting local functions, blocks, and exits into
+ one another.
+ </li>
+</ol></div>
+<h6>
+<a name="boost_localfunction.Release_Notes.h1"></a>
+ <span><a name="boost_localfunction.Release_Notes.version_0_1_1__2011_01_10_"></a></span><a class="link" href="Release_Notes.html#boost_localfunction.Release_Notes.version_0_1_1__2011_01_10_">Version
+ 0.1.1 (2011-01-10)</a>
+ </h6>
+<div class="orderedlist"><ol class="orderedlist" type="1">
+<li class="listitem">
+ Uploaded library source into Boost SVN sandbox.
+ </li>
+<li class="listitem">
+ Fixed prev/next arrows and other minor layouts in documentation.
+ </li>
+<li class="listitem">
+ Added Release section to documentation.
+ </li>
+</ol></div>
+<h6>
+<a name="boost_localfunction.Release_Notes.h2"></a>
+ <span><a name="boost_localfunction.Release_Notes.version_0_1_0__2011_01_03_"></a></span><a class="link" href="Release_Notes.html#boost_localfunction.Release_Notes.version_0_1_0__2011_01_03_">Version
+ 0.1.0 (2011-01-03)</a>
+ </h6>
+<div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
+ Shared with Boost for first round of comments.
+ </li></ol></div>
+<h6>
+<a name="boost_localfunction.Release_Notes.h3"></a>
+ <span><a name="boost_localfunction.Release_Notes.version_0_0_1__2010_12_15_"></a></span><a class="link" href="Release_Notes.html#boost_localfunction.Release_Notes.version_0_0_1__2010_12_15_">Version
+ 0.0.1 (2010-12-15)</a>
+ </h6>
+<div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem">
+ Completed development, examples, and documentation.
+ </li></ol></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 &#169; 2009-2012 Lorenzo
+ Caminiti<p>
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="Implementation.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><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="Bibliography.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>

Added: sandbox/closure/libs/local_function/doc/html/boost_localfunction/Tutorial.html
==============================================================================
--- (empty file)
+++ sandbox/closure/libs/local_function/doc/html/boost_localfunction/Tutorial.html 2012-01-21 13:28:36 EST (Sat, 21 Jan 2012)
@@ -0,0 +1,527 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
+<title>Tutorial</title>
+<link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
+<link rel="home" href="../index.html" title="Chapter&#160;1.&#160;Boost.LocalFunction 1.0.0">
+<link rel="up" href="../index.html" title="Chapter&#160;1.&#160;Boost.LocalFunction 1.0.0">
+<link rel="prev" href="Getting_Started.html" title="Getting Started">
+<link rel="next" href="Advanced_Topics.html" title="Advanced Topics">
+</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">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="Getting_Started.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><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="Advanced_Topics.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_localfunction.Tutorial"></a><a class="link" href="Tutorial.html" title="Tutorial">Tutorial</a>
+</h2></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section">Local Functions</span></dt>
+<dt><span class="section">Binding Variables</span></dt>
+<dt><span class="section"><a href="Tutorial.html#boost_localfunction.Tutorial.binding_the_object__this_">Binding
+ the Object <code class="computeroutput"><span class="keyword">this</span></code></a></span></dt>
+<dt><span class="section">Templates</span></dt>
+</dl></div>
+<p>
+ This section illustrates basic usages of this library.
+ </p>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Tutorial.local_functions"></a><a class="link" href="Tutorial.html#boost_localfunction.Tutorial.local_functions" title="Local Functions">Local Functions</a>
+</h3></div></div></div>
+<p>
+ Local functions are defined using macros from the header file <code class="computeroutput">boost/local_function.hpp</code>. The
+ macros must be used from within a declarative context (this is a limitation
+ with respect to <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ lambda</a> functions which can instead be declared within expressions):
+ </p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">local_function</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="special">...</span>
+<span class="special">{</span> <span class="comment">// Some declarative context.</span>
+ <span class="special">...</span>
+ <span class="emphasis"><em>result-type</em></span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="emphasis"><em>parameters</em></span><span class="special">)</span> <span class="special">{</span>
+ <span class="emphasis"><em>body-code</em></span>
+ <span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="emphasis"><em>name</em></span><span class="special">)</span>
+ <span class="special">...</span>
+<span class="special">}</span>
+</pre>
+<p>
+ The code expanded by the macros declares a function object (or functor)
+ with the local function name specified by <code class="computeroutput">BOOST_LOCAL_FUNCTION_NAME</code>.
+ <sup>[<a name="boost_localfunction.Tutorial.local_functions.f0" href="#ftn.boost_localfunction.Tutorial.local_functions.f0" class="footnote">3</a>]</sup> The usual C++ scope visibility rules apply to local functions
+ for which a local function is visible only within the enclosing scope in
+ which it is declared.
+ </p>
+<p>
+ The local function body is specified in a code block <code class="computeroutput"><span class="special">{</span>
+ <span class="special">...</span> <span class="special">}</span></code>
+ using the usual C++ syntax. The body is specified outside any of the macros
+ so eventual compiler error messages and related line numbers retain their
+ usual meaning and format. <sup>[<a name="boost_localfunction.Tutorial.local_functions.f1" href="#ftn.boost_localfunction.Tutorial.local_functions.f1" class="footnote">4</a>]</sup>
+ </p>
+<p>
+ The local function parameters are passed to the <code class="computeroutput">BOOST_LOCAL_FUNCTION</code>
+ macro as a comma-separated list of tokens (see the <a class="link" href="../">No
+ Variadic Macros</a> section for compilers that do not support variadic
+ macros):
+ </p>
+<pre class="programlisting"><span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><code class="literal"><span class="emphasis"><em>parameter-type1 parameter-name1</em></span></code><span class="special">,</span> <code class="literal"><span class="emphasis"><em>parameter-type2 parameter-name2, ...</em></span></code><span class="special">)</span>
+</pre>
+<p>
+ The maximum number of parameters that can be passed to a local function (excluding
+ eventual bound variables) is controlled at compile-time by the configuration
+ macro <code class="computeroutput">BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX</code>.
+ For example, let's program a local function named <code class="computeroutput"><span class="identifier">add</span></code>
+ that adds together two integers <code class="computeroutput"><span class="identifier">x</span></code>
+ and <code class="computeroutput"><span class="identifier">y</span></code> (see also "add_nobind.cpp"):
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">int</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span> <span class="comment">// Local function.</span>
+ <span class="keyword">return</span> <span class="identifier">x</span> <span class="special">+</span> <span class="identifier">y</span><span class="special">;</span>
+<span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">add</span><span class="special">)</span>
+
+<span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">add</span><span class="special">(</span><span class="number">1</span><span class="special">,</span> <span class="number">2</span><span class="special">)</span> <span class="special">==</span> <span class="number">3</span> <span class="special">);</span> <span class="comment">// Local function call.</span>
+</pre>
+<p>
+ </p>
+<p>
+ If the local function has no parameter, it is possible to pass <code class="computeroutput"><span class="keyword">void</span></code> to the <code class="computeroutput">BOOST_LOCAL_FUNCTION</code>
+ macro (similarly to the C syntax that allows to use <code class="computeroutput"><span class="keyword">int</span>
+ <span class="identifier">f</span><span class="special">(</span><span class="keyword">void</span><span class="special">)</span></code> for
+ a function with no parameter): <sup>[<a name="boost_localfunction.Tutorial.local_functions.f2" href="#ftn.boost_localfunction.Tutorial.local_functions.f2" class="footnote">5</a>]</sup>
+ </p>
+<pre class="programlisting"><span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">void</span><span class="special">)</span> <span class="comment">// No parameter.</span>
+</pre>
+<p>
+ For example, let's program a local function that always returns <code class="computeroutput"><span class="number">10</span></code> (see also "ten.cpp"):
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">void</span><span class="special">)</span> <span class="special">{</span> <span class="comment">// No parameter.</span>
+ <span class="keyword">return</span> <span class="number">10</span><span class="special">;</span>
+<span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">ten</span><span class="special">)</span>
+
+<span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">ten</span><span class="special">()</span> <span class="special">==</span> <span class="number">10</span> <span class="special">);</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Tutorial.Binding"></a><a class="link" href="Tutorial.html#boost_localfunction.Tutorial.Binding" title="Binding Variables">Binding Variables</a>
+</h3></div></div></div>
+<p>
+ Variables in scope (local variables, enclosing function parameters, member
+ variables, etc) can be bound to a local function declaration. Only bound
+ variables, static variables, global variables, functions, and enumerations
+ from the enclosing scope are accessible from within the local function body.
+ The types of bound variables are automatically deduced by this library using
+ Boost.Typeof.
+ <sup>[<a name="boost_localfunction.Tutorial.Binding.f0" href="#ftn.boost_localfunction.Tutorial.Binding.f0" class="footnote">6</a>]</sup>
+ </p>
+<div class="important"><table border="0" summary="Important">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../../doc/src/images/important.png"></td>
+<th align="left">Important</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ The library implementation uses Boost.Typeof
+ to automatically deduce the types of the bound variables. In order to compile
+ code in type-of emulation mode, all types should be properly registered
+ with <code class="computeroutput"><span class="identifier">BOOST_TYPEOF_REGISTER_TYPE</span></code>
+ or <code class="computeroutput"><span class="identifier">BOOST_TYPEOF_REGISTER_TEMPLATE</span></code>
+ macros, or appropriate Boost.Typeof
+ headers should be included (see the Boost.Typeof
+ documentation for more detail).
+ </p></td></tr>
+</table></div>
+<p>
+ This library introduces the new "keyword" <code class="computeroutput"><span class="identifier">bind</span></code>
+ <sup>[<a name="boost_localfunction.Tutorial.Binding.f1" href="#ftn.boost_localfunction.Tutorial.Binding.f1" class="footnote">7</a>]</sup> which is used in place of the parameter type to specify the name
+ of a variable in scope to bind (therefore, <code class="computeroutput"><span class="identifier">bind</span></code>
+ cannot be used as a local function parameter type). A variable can be bound
+ by value:
+ </p>
+<pre class="programlisting"><span class="identifier">bind</span> <span class="emphasis"><em>variable-name</em></span> <span class="comment">// Bind by value.</span>
+</pre>
+<p>
+ Or by reference prefixing the variable name with <code class="computeroutput"><span class="special">&amp;</span></code>:
+ </p>
+<pre class="programlisting"><span class="identifier">bind</span><span class="special">&amp;</span> <span class="emphasis"><em>variable-name</em></span> <span class="comment">// Bind by reference.</span>
+</pre>
+<p>
+ Furthermore, the "keyword" <code class="computeroutput"><span class="identifier">bind</span></code>
+ can be prefixed by <code class="computeroutput"><span class="keyword">const</span></code> to
+ bind the variable by constant value:
+ </p>
+<pre class="programlisting"><span class="keyword">const</span> <span class="identifier">bind</span> <span class="emphasis"><em>variable-name</em></span> <span class="comment">// Bind by constant value.</span>
+</pre>
+<p>
+ Or by constant reference:
+ </p>
+<pre class="programlisting"><span class="keyword">const</span> <span class="identifier">bind</span><span class="special">&amp;</span> <span class="emphasis"><em>variable-name</em></span> <span class="comment">// Bind by constant value.</span>
+</pre>
+<p>
+ Note that when <code class="computeroutput"><span class="keyword">const</span></code> is used,
+ it must always precede <code class="computeroutput"><span class="identifier">bind</span></code>.
+ <sup>[<a name="boost_localfunction.Tutorial.Binding.f2" href="#ftn.boost_localfunction.Tutorial.Binding.f2" class="footnote">8</a>]</sup>
+ </p>
+<p>
+ If a variable is bound by value, then a copy of the variable value is taken
+ at the point of the local function declaration. If a variable is bound by
+ reference instead, the variable will refer to the value it has at the point
+ of the local function call. Furthermore, it is the programmers' responsibility
+ to ensure that variables bound by reference survive the declaration scope
+ of the local function otherwise the bound references will be invalid resulting
+ in undefined behaviour (in other words, the usual care in using C++ references
+ must be taken for variables bound by reference).
+ </p>
+<p>
+ The type of a bound variable is automatically deduced and it is the exact
+ same type used to declare such a variable in the enclosing scope with the
+ following notes:
+ </p>
+<div class="itemizedlist"><ul class="itemizedlist" type="disc">
+<li class="listitem">
+ If a bound variable was declared constant in the enclosing scope, it
+ will be always bound by constant value or constant reference even if
+ <code class="computeroutput"><span class="identifier">bind</span></code> is used instead
+ of <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">bind</span></code>
+ . However, if a bound variable was not declared constant in the enclosing
+ scope then it will not be bound as constant unless constant binding is
+ forced using <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">bind</span></code>.
+ (Note that binding by constant reference is not supported by <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ lambda</a> functions but it is supported by this library.) <sup>[<a name="boost_localfunction.Tutorial.Binding.f3" href="#ftn.boost_localfunction.Tutorial.Binding.f3" class="footnote">9</a>]</sup>
+ </li>
+<li class="listitem">
+ If a bound variable was declared as a reference in the enclosing scope,
+ it will still be bound by value unless it is explicitly bound by reference
+ using <code class="computeroutput"><span class="identifier">bind</span><span class="special">&amp;</span></code>
+ or <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">bind</span><span class="special">&amp;</span></code>. <sup>[<a name="boost_localfunction.Tutorial.Binding.f4" href="#ftn.boost_localfunction.Tutorial.Binding.f4" class="footnote">10</a>]</sup>
+ </li>
+</ul></div>
+<p>
+ As with passing parameters to usual C++ functions, programmers might want
+ to bind variables of complex types by (possibly constant) reference instead
+ than by value to avoid expensive copy operations when these variables are
+ bound to a local function.
+ </p>
+<p>
+ For example, let's program the local function <code class="computeroutput"><span class="identifier">add</span></code>
+ from the example in the <a class="link" href="../">Introduction</a>
+ section. We bind the local variable <code class="computeroutput"><span class="identifier">factor</span></code>
+ by constant value, the local variable <code class="computeroutput"><span class="identifier">sum</span></code>
+ by (non-constant) reference, and program the body to perform the summation
+ (see also "add.cpp"):
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="special">{</span> <span class="comment">// Some local scope.</span>
+ <span class="keyword">int</span> <span class="identifier">sum</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">factor</span> <span class="special">=</span> <span class="number">10</span><span class="special">;</span> <span class="comment">// Variables in scope to bind.</span>
+
+ <span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">bind</span> <span class="identifier">factor</span><span class="special">,</span> <span class="identifier">bind</span><span class="special">&amp;</span> <span class="identifier">sum</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">num</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">sum</span> <span class="special">+=</span> <span class="identifier">factor</span> <span class="special">*</span> <span class="identifier">num</span><span class="special">;</span>
+ <span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">add</span><span class="special">)</span>
+
+ <span class="identifier">add</span><span class="special">(</span><span class="number">1</span><span class="special">);</span> <span class="comment">// Call the local function (with one parameter `num`).</span>
+ <span class="keyword">int</span> <span class="identifier">nums</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span><span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">};</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">nums</span><span class="special">,</span> <span class="identifier">nums</span> <span class="special">+</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">add</span><span class="special">);</span> <span class="comment">// Pass it to an algorithm.</span>
+
+ <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">sum</span> <span class="special">==</span> <span class="number">60</span> <span class="special">);</span> <span class="comment">// Assert final summation value.</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Tutorial.binding_the_object__this_"></a><a class="link" href="Tutorial.html#boost_localfunction.Tutorial.binding_the_object__this_" title="Binding the Object this">Binding
+ the Object <code class="computeroutput"><span class="keyword">this</span></code></a>
+</h3></div></div></div>
+<p>
+ It is also possible to bind the object <code class="computeroutput"><span class="keyword">this</span></code>
+ when it is in scope (e.g., from an enclosing non-static member function).
+ This is done by using the special symbol <code class="computeroutput"><span class="identifier">this_</span></code>
+ <sup>[<a name="boost_localfunction.Tutorial.binding_the_object__this_.f0" href="#ftn.boost_localfunction.Tutorial.binding_the_object__this_.f0" class="footnote">11</a>]</sup> (instead of <code class="computeroutput"><span class="keyword">this</span></code>)
+ <sup>[<a name="boost_localfunction.Tutorial.binding_the_object__this_.f1" href="#ftn.boost_localfunction.Tutorial.binding_the_object__this_.f1" class="footnote">12</a>]</sup> as the name of the variable to bind in the local function declaration
+ and also to access the object within the local function body.
+ </p>
+<p>
+ The object <code class="computeroutput"><span class="keyword">this</span></code> can be bound
+ by value:
+ </p>
+<pre class="programlisting"><span class="identifier">bind</span> <span class="identifier">this_</span> <span class="comment">// Bind the object `this` by value.</span>
+</pre>
+<p>
+ In this case the local function will be able to modify the object when the
+ enclosing scope is not a constant member and it will not be able to modify
+ the object when the enclosing scope is a constant member. Otherwise, the
+ object <code class="computeroutput"><span class="keyword">this</span></code> can be bound by
+ constant value:
+ </p>
+<pre class="programlisting"><span class="keyword">const</span> <span class="identifier">bind</span> <span class="identifier">this_</span> <span class="comment">// Bind the object `this` by constant value.</span>
+</pre>
+<p>
+ In this case the local function will never be able to modify the object (regardless
+ of whether the enclosing scope is a constant member or not).
+ </p>
+<p>
+ Note that the object <code class="computeroutput"><span class="keyword">this</span></code> can
+ never be bound by reference because C++ does not allow to obtain a reference
+ to <code class="computeroutput"><span class="keyword">this</span></code> (the library will generate
+ a compile-time error if programmers try to use <code class="computeroutput"><span class="identifier">bind</span><span class="special">&amp;</span> <span class="keyword">this</span></code>
+ or <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">bind</span><span class="special">&amp;</span> <span class="keyword">this</span></code>).
+ Note that <code class="computeroutput"><span class="keyword">this</span></code> is a pointer
+ so the pointed object is never copied even if <code class="computeroutput"><span class="keyword">this</span></code>
+ is bound by value (also it is not allowed to directly bind <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code> because
+ <code class="computeroutput"><span class="special">*</span><span class="keyword">this</span></code>
+ is an expression and not a valid name of a variable in scope).
+ </p>
+<div class="warning"><table border="0" summary="Warning">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../doc/src/images/warning.png"></td>
+<th align="left">Warning</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ Unfortunately, mistakenly using <code class="computeroutput"><span class="keyword">this</span></code>
+ within the local function body instead of <code class="computeroutput"><span class="identifier">this_</span></code>
+ leads to undefined behaviour and it will not necessarily generate a compile-time
+ error. <sup>[<a name="boost_localfunction.Tutorial.binding_the_object__this_.f2" href="#ftn.boost_localfunction.Tutorial.binding_the_object__this_.f2" class="footnote">13</a>]</sup> Programmers are responsible to make sure that <code class="computeroutput"><span class="keyword">this</span></code> is never used within a local function
+ body which should only use the special symbol <code class="computeroutput"><span class="identifier">this_</span></code>.
+ </p></td></tr>
+</table></div>
+<p>
+ For example, let's program a local function <code class="computeroutput"><span class="identifier">add</span></code>
+ similar to the one in the example from the <a class="link" href="../">Introduction</a>
+ section but using a member function to illustrate how to bind the object
+ <code class="computeroutput"><span class="keyword">this</span></code> (see also "add_this.cpp"):
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">adder</span> <span class="special">{</span>
+ <span class="identifier">adder</span><span class="special">():</span> <span class="identifier">sum_</span><span class="special">(</span><span class="number">0</span><span class="special">)</span> <span class="special">{}</span>
+
+ <span class="keyword">int</span> <span class="identifier">sum</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;&amp;</span> <span class="identifier">nums</span><span class="special">,</span> <span class="keyword">const</span> <span class="keyword">int</span> <span class="identifier">factor</span> <span class="special">=</span> <span class="number">10</span><span class="special">)</span> <span class="special">{</span>
+
+ <span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">bind</span> <span class="identifier">factor</span><span class="special">,</span> <span class="identifier">bind</span> <span class="identifier">this_</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">num</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">this_</span><span class="special">-&gt;</span><span class="identifier">sum_</span> <span class="special">+=</span> <span class="identifier">factor</span> <span class="special">*</span> <span class="identifier">num</span><span class="special">;</span> <span class="comment">// Use `this_` instead of `this`.</span>
+ <span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">add</span><span class="special">)</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">nums</span><span class="special">.</span><span class="identifier">begin</span><span class="special">(),</span> <span class="identifier">nums</span><span class="special">.</span><span class="identifier">end</span><span class="special">(),</span> <span class="identifier">add</span><span class="special">);</span>
+ <span class="keyword">return</span> <span class="identifier">sum_</span><span class="special">;</span>
+ <span class="special">}</span>
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="keyword">int</span> <span class="identifier">sum_</span><span class="special">;</span>
+<span class="special">};</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="section">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_localfunction.Tutorial.templates"></a><a class="link" href="Tutorial.html#boost_localfunction.Tutorial.templates" title="Templates">Templates</a>
+</h3></div></div></div>
+<p>
+ When local functions are programmed within templates, they need to be declared
+ using the special macro <code class="computeroutput">BOOST_LOCAL_FUNCTION_TPL</code>
+ (see the Reference section): <sup>[<a name="boost_localfunction.Tutorial.templates.f0" href="#ftn.boost_localfunction.Tutorial.templates.f0" class="footnote">14</a>]</sup>
+ </p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">local_function</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
+
+<span class="special">...</span>
+<span class="special">{</span> <span class="comment">// Some declarative context within a template.</span>
+ <span class="special">...</span>
+ <span class="emphasis"><em>result-type</em></span> <span class="identifier">BOOST_LOCAL_FUNCTION_TPL</span><span class="special">(</span><span class="emphasis"><em>parameters</em></span><span class="special">)</span> <span class="special">{</span>
+ <span class="emphasis"><em>body-code</em></span>
+ <span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="emphasis"><em>name</em></span><span class="special">)</span>
+ <span class="special">...</span>
+<span class="special">}</span>
+</pre>
+<p>
+ The <code class="computeroutput">BOOST_LOCAL_FUNCTION_TPL</code>
+ macro has the exact same syntax of the <code class="computeroutput">BOOST_LOCAL_FUNCTION</code>
+ macro that we have seen so far.
+ </p>
+<p>
+ For example, let's rewrite a local function similar to the one from the
+ <a class="link" href="../">Introduction</a> section but
+ wrapped within a template:
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> <span class="identifier">T</span><span class="special">&gt;</span>
+<span class="identifier">T</span> <span class="identifier">total</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">y</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">T</span><span class="special">&amp;</span> <span class="identifier">z</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">T</span> <span class="identifier">sum</span> <span class="special">=</span> <span class="identifier">T</span><span class="special">(),</span> <span class="identifier">factor</span> <span class="special">=</span> <span class="number">10</span><span class="special">;</span>
+
+ <span class="comment">// Using the `..._TPL` macro.</span>
+ <span class="identifier">T</span> <span class="identifier">BOOST_LOCAL_FUNCTION_TPL</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">bind</span> <span class="identifier">factor</span><span class="special">,</span> <span class="identifier">bind</span><span class="special">&amp;</span> <span class="identifier">sum</span><span class="special">,</span> <span class="identifier">T</span> <span class="identifier">num</span><span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">sum</span> <span class="special">+=</span> <span class="identifier">factor</span> <span class="special">*</span> <span class="identifier">num</span><span class="special">;</span>
+ <span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">add</span><span class="special">)</span>
+
+ <span class="identifier">add</span><span class="special">(</span><span class="identifier">x</span><span class="special">);</span>
+
+ <span class="identifier">T</span> <span class="identifier">nums</span><span class="special">[</span><span class="number">2</span><span class="special">];</span> <span class="identifier">nums</span><span class="special">[</span><span class="number">0</span><span class="special">]</span> <span class="special">=</span> <span class="identifier">y</span><span class="special">;</span> <span class="identifier">nums</span><span class="special">[</span><span class="number">1</span><span class="special">]</span> <span class="special">=</span> <span class="identifier">z</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">nums</span><span class="special">,</span> <span class="identifier">nums</span> <span class="special">+</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">add</span><span class="special">);</span>
+
+ <span class="keyword">return</span> <span class="identifier">sum</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+</div>
+<div class="footnotes">
+<br><hr width="100" align="left">
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.local_functions.f0" href="#boost_localfunction.Tutorial.local_functions.f0" class="para">3</a>] </sup>
+ <span class="bold"><strong>Rationale.</strong></span> The local function name must
+ be passed to the macro <code class="computeroutput">BOOST_LOCAL_FUNCTION_NAME</code>
+ ending the function definition so this macro can declare a local variable
+ with the local function name to hold the local function object.
+ </p></div>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.local_functions.f1" href="#boost_localfunction.Tutorial.local_functions.f1" class="para">4</a>] </sup>
+ <span class="bold"><strong>Rationale.</strong></span> If the local function body
+ were instead passed as a macro parameter, it would be expanded on a single
+ line of code (because macros always expand as a single line of code). Therefore,
+ eventual compiler error line numbers would all report the same value and
+ would no longer be useful to pinpoint the error.
+ </p></div>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.local_functions.f2" href="#boost_localfunction.Tutorial.local_functions.f2" class="para">5</a>] </sup>
+ <span class="bold"><strong>Rationale.</strong></span> The C++03
+ standard does not allow pass empty parameters to a macro so the macro cannot
+ be invoked as <code class="computeroutput"><span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">()</span></code>. On C99
+ compilers with properly implemented empty macro parameter support it would
+ be possible to allow <code class="computeroutput"><span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">()</span></code> but this is already not the case for
+ MSVC so this syntax is never allowed to ensure better portability.
+ </p></div>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.Binding.f0" href="#boost_localfunction.Tutorial.Binding.f0" class="para">6</a>] </sup>
+ <span class="bold"><strong>Rationale.</strong></span> By binding a variable in scope,
+ the local function declaration is specifying that such a variable should
+ be accessible within the local function body regardless of its type. Semantically,
+ this binding should be seen as an "extension" of the scope of
+ the bound variable from the enclosing scope to the scope of the local function
+ body. Therefore, contrary to the semantic of passing a function parameter,
+ the semantic of binding a variable does not depend on the variable type
+ but just on the variable name: "The variable in scope named <span class="emphasis"><em>x</em></span>
+ should be accessible within the local function named <span class="emphasis"><em>f</em></span>".
+ For example, this is useful for maintenance because if a bound variable
+ type is changed, the local function declaration does not have to change.
+ </p></div>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.Binding.f1" href="#boost_localfunction.Tutorial.Binding.f1" class="para">7</a>] </sup>
+ Obviously, the token <code class="computeroutput"><span class="identifier">bind</span></code>
+ is not a keyword of the C++ language. This library parses the token <code class="computeroutput"><span class="identifier">bind</span></code> during macro expansion using preprocessor
+ metaprogramming (see the <a class="link" href="../">Implementation</a>
+ section). Therefore, <code class="computeroutput"><span class="identifier">bind</span></code>
+ can be considered a new "keyword" only at the preprocessor metaprogramming
+ level within the syntax defined by the macros of this library- thus it
+ is referred to as a "keyword" only within quotes.
+ </p></div>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.Binding.f2" href="#boost_localfunction.Tutorial.Binding.f2" class="para">8</a>] </sup>
+ <span class="bold"><strong>Rationale.</strong></span> The library macros could have
+ been implemented to accept both syntaxes <code class="computeroutput"><span class="keyword">const</span>
+ <span class="identifier">bind</span> <span class="special">...</span></code>
+ and <code class="computeroutput"><span class="identifier">bind</span> <span class="keyword">const</span>
+ <span class="special">...</span></code> equivalently. However, handling
+ both syntaxes would have complicated the macro implementation without adding
+ any feature so only one syntax (<code class="computeroutput"><span class="keyword">const</span>
+ <span class="identifier">bind</span> <span class="special">...</span></code>)
+ is supported.
+ </p></div>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.Binding.f3" href="#boost_localfunction.Tutorial.Binding.f3" class="para">9</a>] </sup>
+ An historical note: Constant binding of variables in scope was the
+ main use case that originally motivated the authors in developing this
+ library. The authors needed to locally create a chuck of code to assert
+ some correctness conditions while these assertions were not supposed
+ to modify any of the variables they were using (see the Contract++
+ library). This was achieved by binding by constant reference <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">bind</span><span class="special">&amp;</span></code> the variables needed by the assertions
+ and then by programming the local function body to check the assertions.
+ This way if any of the assertions mistakenly changes a bound variable
+ (for example confusing the operator <code class="computeroutput"><span class="special">==</span></code>
+ with <code class="computeroutput"><span class="special">=</span></code>), the compiler
+ correctly generates an error because the bound variable is of <code class="computeroutput"><span class="keyword">const</span></code> type within the local function
+ body.
+ </p></div>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.Binding.f4" href="#boost_localfunction.Tutorial.Binding.f4" class="para">10</a>] </sup>
+ <span class="bold"><strong>Rationale.</strong></span> Variables originally declared
+ as references are bound by value unless <code class="computeroutput"><span class="special">[</span><span class="keyword">const</span><span class="special">]</span> <span class="identifier">bind</span><span class="special">&amp;</span></code>
+ is used so that references can be bound by both value <code class="computeroutput"><span class="special">[</span><span class="keyword">const</span><span class="special">]</span> <span class="identifier">bind</span></code>
+ and reference <code class="computeroutput"><span class="special">[</span><span class="keyword">const</span><span class="special">]</span> <span class="identifier">bind</span><span class="special">&amp;</span></code> (this is the same binding semantic
+ adopted by Boost.ScopeExit).
+ On the other hand, variables originally declared as constants should
+ never loose their <code class="computeroutput"><span class="keyword">const</span></code>
+ qualifier (to prevent their modification not just in the enclosing
+ scope but also in the local scope) thus they are always bound by constant
+ even if <code class="computeroutput"><span class="identifier">bind</span><span class="special">[&amp;]</span></code>
+ is used instead of <code class="computeroutput"><span class="keyword">const</span> <span class="identifier">bind</span><span class="special">[&amp;]</span></code>.
+ </p></div>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.binding_the_object__this_.f0" href="#boost_localfunction.Tutorial.binding_the_object__this_.f0" class="para">11</a>] </sup>
+ <span class="bold"><strong>Rationale.</strong></span> The special name <code class="computeroutput"><span class="identifier">this_</span></code> was chosen following <a href="http://boost.2283326.n4.nabble.com/local-this-or-this-td3423912.html" target="_top">Boost
+ practises</a> which postfix with an underscore identifiers that are
+ named after keywords (the C++ keyword <code class="computeroutput"><span class="keyword">this</span></code>
+ in this case).
+ </p></div>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.binding_the_object__this_.f1" href="#boost_localfunction.Tutorial.binding_the_object__this_.f1" class="para">12</a>] </sup>
+ <span class="bold"><strong>Rationale.</strong></span> This limitation comes from
+ the fact that <code class="computeroutput"><span class="keyword">this</span></code> is a reserved
+ C++ keyword so it cannot be used as the name of the internal parameter
+ that passes the bound object to the local function body. It would have
+ been possible to use <code class="computeroutput"><span class="keyword">this</span></code>
+ (instead of <code class="computeroutput"><span class="identifier">this_</span></code>) within
+ the local function body either at the expenses of copying the bound object
+ (which would introduce run-time overhead and also the stringent requirement
+ that the bound object must have a deep copy constructor) or by relying
+ on an <a href="http://groups.google.com/group/comp.lang.c++.moderated/browse_thread/thread/d3a86f27277f713b" target="_top">undefined
+ behaviour of <code class="computeroutput"><span class="keyword">static_cast</span></code></a>
+ (which might not work on all platforms at the cost of portability).
+ </p></div>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.binding_the_object__this_.f2" href="#boost_localfunction.Tutorial.binding_the_object__this_.f2" class="para">13</a>] </sup>
+ <span class="bold"><strong>Rationale.</strong></span> The local function body cannot
+ be a static member function of the local functor object in order to support
+ recursion (because the local function name is specified by the <code class="computeroutput">BOOST_LOCAL_FUNCTION_NAME</code>
+ macro only after the body so it must be made available via a functor
+ member variable named after the local function and local classes cannot
+ have static member variables in C++) and nesting (because the argument
+ binding variable must be declared as a member variable so it is visible
+ in a local function nested within the body member function) -- see the
+ <a class="link" href="../">Implementation</a> section.
+ Therefore, from within the local function body the variable <code class="computeroutput"><span class="keyword">this</span></code> is visible but it refers to the local
+ functor and not to the bound object.
+ </p></div>
+<div class="footnote"><p><sup>[<a id="ftn.boost_localfunction.Tutorial.templates.f0" href="#boost_localfunction.Tutorial.templates.f0" class="para">14</a>] </sup>
+ <span class="bold"><strong>Rationale.</strong></span> Within templates, this library
+ needs to use <code class="computeroutput"><span class="keyword">typename</span></code> to explicitly
+ indicate that some expressions evaluate to a type. Because C++03
+ does not allow to use <code class="computeroutput"><span class="keyword">typename</span></code>
+ outside templates, the special <code class="computeroutput"><span class="identifier">TPL</span></code>
+ macro is used to indicate that the enclosing scope is a template so this
+ library can safely use <code class="computeroutput"><span class="keyword">typename</span></code>
+ to resolve expression type ambiguities.
+ </p></div>
+</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 &#169; 2009-2012 Lorenzo
+ Caminiti<p>
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="Getting_Started.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><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="Advanced_Topics.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>

Added: sandbox/closure/libs/local_function/doc/html/index.html
==============================================================================
--- (empty file)
+++ sandbox/closure/libs/local_function/doc/html/index.html 2012-01-21 13:28:36 EST (Sat, 21 Jan 2012)
@@ -0,0 +1,230 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
+<title>Chapter&#160;1.&#160;Boost.LocalFunction 1.0.0</title>
+<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
+<link rel="home" href="index.html" title="Chapter&#160;1.&#160;Boost.LocalFunction 1.0.0">
+<link rel="next" href="boost_localfunction/Getting_Started.html" title="Getting Started">
+</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">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav"><a accesskey="n" href="boost_localfunction/Getting_Started.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a></div>
+<div class="chapter">
+<div class="titlepage"><div>
+<div><h2 class="title">
+<a name="local_function"></a>Chapter&#160;1.&#160;Boost.LocalFunction 1.0.0 </h2></div>
+<div><div class="author"><h3 class="author">
+<span class="firstname">Lorenzo</span> <span class="surname">Caminiti <code class="email">&lt;<a class="email" href="mailto:lorcaminiti_at_[hidden]">lorcaminiti_at_[hidden]</a>&gt;</code></span>
+</h3></div></div>
+<div><p class="copyright">Copyright &#169; 2009-2012 Lorenzo
+ Caminiti</p></div>
+<div><div class="legalnotice">
+<a name="local_function.legal"></a><p>
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+ </p>
+</div></div>
+</div></div>
+<div class="toc">
+<p><b>Table of Contents</b></p>
+<dl>
+<dt><span class="section">Introduction</span></dt>
+<dt><span class="section">Getting Started</span></dt>
+<dd><dl>
+<dt><span class="section"><a href="boost_localfunction/Getting_Started.html#boost_localfunction.Getting_Started.this_documentation">This
+ Documentation</a></span></dt>
+<dt><span class="section"><a href="boost_localfunction/Getting_Started.html#boost_localfunction.Getting_Started.compilers_and_platforms">Compilers
+ and Platforms</a></span></dt>
+<dt><span class="section">Installation</span></dt>
+<dt><span class="section"><a href="boost_localfunction/Getting_Started.html#boost_localfunction.Getting_Started.compile_time_configuration">Compile-Time
+ Configuration</a></span></dt>
+</dl></dd>
+<dt><span class="section">Tutorial</span></dt>
+<dd><dl>
+<dt><span class="section">Local Functions</span></dt>
+<dt><span class="section">Binding Variables</span></dt>
+<dt><span class="section"><a href="boost_localfunction/Tutorial.html#boost_localfunction.Tutorial.binding_the_object__this_">Binding
+ the Object <code class="computeroutput"><span class="keyword">this</span></code></a></span></dt>
+<dt><span class="section">Templates</span></dt>
+</dl></dd>
+<dt><span class="section">Advanced Topics</span></dt>
+<dd><dl>
+<dt><span class="section"><a href="boost_localfunction/Advanced_Topics.html#boost_localfunction.Advanced_Topics.default_parameters">Default
+ Parameters</a></span></dt>
+<dt><span class="section"><a href="boost_localfunction/Advanced_Topics.html#boost_localfunction.Advanced_Topics.commas_and_symbols_in_macros">Commas
+ and Symbols in Macros</a></span></dt>
+<dt><span class="section"><a href="boost_localfunction/Advanced_Topics.html#boost_localfunction.Advanced_Topics.assigning_and_returning">Assigning
+ and Returning</a></span></dt>
+<dt><span class="section">Nesting</span></dt>
+<dt><span class="section"><a href="boost_localfunction/Advanced_Topics.html#boost_localfunction.Advanced_Topics.deducing_bound_types__concepts__etc_">Deducing
+ Bound Types (concepts, etc)</a></span></dt>
+<dt><span class="section"><a href="boost_localfunction/Advanced_Topics.html#boost_localfunction.Advanced_Topics.specifying_types">Specifying
+ Types</a></span></dt>
+<dt><span class="section">Inlining</span></dt>
+<dt><span class="section">Recursion</span></dt>
+<dt><span class="section">Overloading</span></dt>
+<dt><span class="section"><a href="boost_localfunction/Advanced_Topics.html#boost_localfunction.Advanced_Topics.exception_specifications">Exception
+ Specifications</a></span></dt>
+<dt><span class="section"><a href="boost_localfunction/Advanced_Topics.html#boost_localfunction.Advanced_Topics.storage_classifiers___auto__and__register__">Storage
+ Classifiers (<code class="computeroutput"><span class="keyword">auto</span></code> and <code class="computeroutput"><span class="keyword">register</span></code>)</a></span></dt>
+<dt><span class="section"><a href="boost_localfunction/Advanced_Topics.html#boost_localfunction.Advanced_Topics.limitations__operators__etc_">Limitations
+ (operators, etc)</a></span></dt>
+</dl></dd>
+<dt><span class="section">Appendix: Examples</span></dt>
+<dd><dl>
+<dt><span class="section"><a href="boost_localfunction/Examples.html#boost_localfunction.Examples.gcc_lambdas__without_c__11_">GCC
+ Lambdas (Without C++11)</a></span></dt>
+<dt><span class="section"><a href="boost_localfunction/Examples.html#boost_localfunction.Examples.constant_blocks">Constant
+ Blocks</a></span></dt>
+<dt><span class="section">Scope Exits</span></dt>
+<dt><span class="section"><a href="boost_localfunction/Examples.html#boost_localfunction.Examples.gcc_nested_functions">GCC
+ Nested Functions</a></span></dt>
+<dt><span class="section">N-Papers</span></dt>
+</dl></dd>
+<dt><span class="section">Appendix: Alternatives</span></dt>
+<dd><dl>
+<dt><span class="section">Features</span></dt>
+<dt><span class="section">Performances</span></dt>
+</dl></dd>
+<dt><span class="section"><a href="boost_localfunction/No_Variadic_Macros.html">Annex: No Variadic
+ Macros</a></span></dt>
+<dd><dl>
+<dt><span class="section"><a href="boost_localfunction/No_Variadic_Macros.html#boost_localfunction.No_Variadic_Macros.sequence_syntax">Sequence
+ Syntax</a></span></dt>
+<dt><span class="section">Examples</span></dt>
+</dl></dd>
+<dt><span class="section">Appendix: Implementation</span></dt>
+<dd><dl>
+<dt><span class="section"><a href="boost_localfunction/Implementation.html#boost_localfunction.Implementation.local_classes_as_template_parameters">Local
+ Classes as Template Parameters</a></span></dt>
+<dt><span class="section"><a href="boost_localfunction/Implementation.html#boost_localfunction.Implementation.parsing_macros">Parsing
+ Macros</a></span></dt>
+<dt><span class="section"><a href="boost_localfunction/Implementation.html#boost_localfunction.Implementation.local_functions">Local
+ Functions</a></span></dt>
+</dl></dd>
+<dt><span class="section">Release Notes</span></dt>
+<dt><span class="section">Bibliography</span></dt>
+<dt><span class="section">Acknowledgments</span></dt>
+</dl>
+</div>
+<p>
+ This library allows to declare functions at local scope within an enclosing function.
+ </p>
+<div class="section">
+<div class="titlepage"><div><div><h2 class="title" style="clear: both">
+<a name="boost_localfunction.Introduction"></a><a class="link" href="index.html#boost_localfunction.Introduction" title="Introduction">Introduction</a>
+</h2></div></div></div>
+<p>
+ <span class="emphasis"><em>Local functions</em></span> are a form of <span class="emphasis"><em>information hiding</em></span>
+ and are useful for dividing procedural tasks into subtasks which are only meaningful
+ locally, avoiding cluttering other parts of the program with functions, variables,
+ etc unrelated to those parts. Local functions therefore complement other structuring
+ possibilities such as namespaces and classes. Local functions are a feature
+ of many programming languages, notably Pascal
+ and Ada,
+ yet lacking from C++03
+ (see also [N2511]).
+ </p>
+<p>
+ Using <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ lambda</a> functions, it is possible to implement local functions by naming
+ the lambdas assigning them to local variables. For example (see also "add_lambda.cpp"):
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="special">{</span> <span class="comment">// Some local scope.</span>
+ <span class="keyword">int</span> <span class="identifier">sum</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">factor</span> <span class="special">=</span> <span class="number">10</span><span class="special">;</span> <span class="comment">// Variables in scope to bind.</span>
+
+ <span class="keyword">auto</span> <span class="identifier">add</span> <span class="special">=</span> <span class="special">[</span><span class="identifier">factor</span><span class="special">,</span> <span class="special">&amp;</span><span class="identifier">sum</span><span class="special">](</span><span class="keyword">int</span> <span class="identifier">num</span><span class="special">)</span> <span class="special">{</span> <span class="comment">// C++11 only.</span>
+ <span class="identifier">sum</span> <span class="special">+=</span> <span class="identifier">factor</span> <span class="special">*</span> <span class="identifier">num</span><span class="special">;</span>
+ <span class="special">};</span>
+
+ <span class="identifier">add</span><span class="special">(</span><span class="number">1</span><span class="special">);</span> <span class="comment">// Call the lambda (with one parameter `num`).</span>
+ <span class="keyword">int</span> <span class="identifier">nums</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span><span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">};</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">nums</span><span class="special">,</span> <span class="identifier">nums</span> <span class="special">+</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">add</span><span class="special">);</span> <span class="comment">// Pass it to an algorithm.</span>
+
+ <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">sum</span> <span class="special">==</span> <span class="number">60</span> <span class="special">);</span> <span class="comment">// Assert final summation value.</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+<p>
+ This library allows to program local functions portably between C++03
+ and C++11 (and
+ with performances comparable to lambdas on C++11
+ compilers, see the <a class="link" href="">Alternatives</a>
+ section). For example (see also "add.cpp"):
+ </p>
+<p>
+</p>
+<pre class="programlisting"><span class="special">{</span> <span class="comment">// Some local scope.</span>
+ <span class="keyword">int</span> <span class="identifier">sum</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">factor</span> <span class="special">=</span> <span class="number">10</span><span class="special">;</span> <span class="comment">// Variables in scope to bind.</span>
+
+ <span class="keyword">void</span> <span class="identifier">BOOST_LOCAL_FUNCTION</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">bind</span> <span class="identifier">factor</span><span class="special">,</span> <span class="identifier">bind</span><span class="special">&amp;</span> <span class="identifier">sum</span><span class="special">,</span> <span class="keyword">int</span> <span class="identifier">num</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">sum</span> <span class="special">+=</span> <span class="identifier">factor</span> <span class="special">*</span> <span class="identifier">num</span><span class="special">;</span>
+ <span class="special">}</span> <span class="identifier">BOOST_LOCAL_FUNCTION_NAME</span><span class="special">(</span><span class="identifier">add</span><span class="special">)</span>
+
+ <span class="identifier">add</span><span class="special">(</span><span class="number">1</span><span class="special">);</span> <span class="comment">// Call the local function (with one parameter `num`).</span>
+ <span class="keyword">int</span> <span class="identifier">nums</span><span class="special">[]</span> <span class="special">=</span> <span class="special">{</span><span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">};</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">for_each</span><span class="special">(</span><span class="identifier">nums</span><span class="special">,</span> <span class="identifier">nums</span> <span class="special">+</span> <span class="number">2</span><span class="special">,</span> <span class="identifier">add</span><span class="special">);</span> <span class="comment">// Pass it to an algorithm.</span>
+
+ <span class="identifier">BOOST_CHECK</span><span class="special">(</span> <span class="identifier">sum</span> <span class="special">==</span> <span class="number">60</span> <span class="special">);</span> <span class="comment">// Assert final summation value.</span>
+<span class="special">}</span>
+</pre>
+<p>
+ </p>
+<p>
+ This library supports the following features for local functions:
+ </p>
+<div class="itemizedlist"><ul class="itemizedlist" type="disc">
+<li class="listitem">
+ Local functions can capture, or better bind,
+ any of the variables from the enclosing scope (a function together with
+ its captured variables is also called a closure).
+ </li>
+<li class="listitem">
+ The local function body is programmed using the usual C++ statement syntax
+ (as a consequence, compiler error messages retain their usual meaning and
+ format).
+ </li>
+<li class="listitem">
+ Local functions can be passed as template parameters so they can be conveniently
+ passed to STL algorithms, etc (this is a strength with respect to C++03
+ functors implemented using local classes, see [N2657]
+ and the <a class="link" href="">Alternatives</a> section).
+ </li>
+<li class="listitem">
+ However, local functions must be defined within a declarative context (e.g.,
+ at a point in the code where local variables can be declared) thus they
+ cannot be defined within expressions (this is a weakness with respect to
+ <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ lambda</a> functions, see the <a class="link" href="">Alternatives</a>
+ section).
+ </li>
+</ul></div>
+<p>
+ See the <a class="link" href="">Alternatives</a> section
+ for a comparison between this library, <a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions" target="_top">C++11
+ lambda</a> functions, Boost.Phoenix,
+ and other C++ techniques implementing related features.
+ </p>
+</div>
+<span style="color: red">&lt;xi:include&gt;&lt;/xi:include&gt;</span>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"><p><small>Last revised: January 21, 2012 at 18:28:00 GMT</small></p></td>
+<td align="right"><div class="copyright-footer"></div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav"><a accesskey="n" href="boost_localfunction/Getting_Started.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a></div>
+</body>
+</html>


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk