3 <meta http-equiv=
"Content-Type" content=
"text/html; charset=US-ASCII">
4 <title>Macro BOOST_LOCAL_FUNCTION
</title>
5 <link rel=
"stylesheet" href=
"../../../../doc/src/boostbook.css" type=
"text/css">
6 <meta name=
"generator" content=
"DocBook XSL Stylesheets V1.78.1">
7 <link rel=
"home" href=
"index.html" title=
"Chapter 1. Boost.LocalFunction 1.0.0">
8 <link rel=
"up" href=
"reference.html#header.boost.local_function_hpp" title=
"Header <boost/local_function.hpp>">
9 <link rel=
"prev" href=
"reference.html" title=
"Reference">
10 <link rel=
"next" href=
"BOOST_LOCAL_FUNCTION_TPL.html" title=
"Macro BOOST_LOCAL_FUNCTION_TPL">
12 <body bgcolor=
"white" text=
"black" link=
"#0000FF" vlink=
"#840084" alink=
"#0000FF">
13 <table cellpadding=
"2" width=
"100%"><tr>
14 <td valign=
"top"><img alt=
"Boost C++ Libraries" width=
"277" height=
"86" src=
"../../../../boost.png"></td>
15 <td align=
"center"><a href=
"../../../../index.html">Home
</a></td>
16 <td align=
"center"><a href=
"../../../../libs/libraries.htm">Libraries
</a></td>
17 <td align=
"center"><a href=
"http://www.boost.org/users/people.html">People
</a></td>
18 <td align=
"center"><a href=
"http://www.boost.org/users/faq.html">FAQ
</a></td>
19 <td align=
"center"><a href=
"../../../../more/index.htm">More
</a></td>
22 <div class=
"spirit-nav">
23 <a accesskey=
"p" href=
"reference.html"><img src=
"../../../../doc/src/images/prev.png" alt=
"Prev"></a><a accesskey=
"u" href=
"reference.html#header.boost.local_function_hpp"><img src=
"../../../../doc/src/images/up.png" alt=
"Up"></a><a accesskey=
"h" href=
"index.html"><img src=
"../../../../doc/src/images/home.png" alt=
"Home"></a><a accesskey=
"n" href=
"BOOST_LOCAL_FUNCTION_TPL.html"><img src=
"../../../../doc/src/images/next.png" alt=
"Next"></a>
25 <div class=
"refentry">
26 <a name=
"BOOST_LOCAL_FUNCTION"></a><div class=
"titlepage"></div>
27 <div class=
"refnamediv">
28 <h2><span class=
"refentrytitle">Macro BOOST_LOCAL_FUNCTION
</span></h2>
29 <p>BOOST_LOCAL_FUNCTION
— This macro is used to start a local function declaration.
</p>
31 <h2 xmlns:
rev=
"http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class=
"refsynopsisdiv-title">Synopsis
</h2>
32 <div xmlns:
rev=
"http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class=
"refsynopsisdiv"><pre class=
"synopsis"><span class=
"comment">// In header:
<<a class=
"link" href=
"reference.html#header.boost.local_function_hpp" title=
"Header <boost/local_function.hpp>">boost/local_function.hpp
</a>>
34 </span>BOOST_LOCAL_FUNCTION(declarations)
</pre></div>
35 <div class=
"refsect1">
36 <a name=
"id903895"></a><h2>Description
</h2>
37 <p>This macro must be used within a declarative context, it must follow the local function result type, it must be followed by the local function body code, and then by the
<code class=
"computeroutput"><a class=
"link" href=
"BOOST_LOCAL_FUNCTION_NAME.html" title=
"Macro BOOST_LOCAL_FUNCTION_NAME">BOOST_LOCAL_FUNCTION_NAME
</a></code> macro (see the
<a class=
"link" href=
"boost_localfunction/tutorial.html" title=
"Tutorial"> Tutorial
</a> and
<a class=
"link" href=
"boost_localfunction/advanced_topics.html" title=
"Advanced Topics"> Advanced Topics
</a> sections):
</p>
38 <pre class=
"programlisting"><span class=
"special">{
</span> <span class=
"comment">// Some declarative context.
</span>
39 <span class=
"special">...
</span>
40 <span class=
"identifier">result_type
</span> <span class=
"identifier">BOOST_LOCAL_FUNCTION
</span><span class=
"special">(
</span><span class=
"identifier">declarations
</span><span class=
"special">)
</span> <span class=
"special">{
</span>
41 <span class=
"special">...
</span> <span class=
"comment">// Body code.
</span>
42 <span class=
"special">}
</span> <span class=
"identifier">BOOST_LOCAL_FUNCTION_NAME
</span><span class=
"special">(
</span><span class=
"identifier">qualified_name
</span><span class=
"special">)
</span>
43 <span class=
"special">...
</span>
44 <span class=
"special">}
</span>
46 <p>As usual, exceptions specifications can be optionally programmed just after the macro and before the body code block
<code class=
"computeroutput">{ ... }
</code> (but the exception specifications will only apply to the body code and not to the library code automatically generated by the macro expansion, see the
<a class=
"link" href=
"boost_localfunction/advanced_topics.html" title=
"Advanced Topics"> Advanced Topics
</a> section).
</p>
47 <p>Within templates, the special macros
<code class=
"computeroutput"><a class=
"link" href=
"BOOST_LOCAL_FUNCTION_TPL.html" title=
"Macro BOOST_LOCAL_FUNCTION_TPL">BOOST_LOCAL_FUNCTION_TPL
</a></code> and
<code class=
"computeroutput"><a class=
"link" href=
"BOOST_LOCAL_FUNCTION_NAME_TPL.html" title=
"Macro BOOST_LOCAL_FUNCTION_NAME_TPL">BOOST_LOCAL_FUNCTION_NAME_TPL
</a></code> must be used.
</p>
48 <p><span class=
"bold"><strong>Parameters:
</strong></span> </p>
49 <div class=
"informaltable"><table class=
"table">
55 <td><span class=
"bold"><strong><code class=
"computeroutput">declarations
</code></strong></span></td>
56 <td>On compilers that support variadic macros, the parameter declarations are defined by the following grammar:
<pre xmlns:
rev=
"http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class=
"table-programlisting"><span class=
"identifier">declarations
</span><span class=
"special">:
</span>
57 <span class=
"keyword">void
</span> <span class=
"special">|
</span> <span class=
"identifier">declaration_tuple
</span> <span class=
"special">|
</span> <span class=
"identifier">declaration_sequence
</span>
58 <span class=
"identifier">declaration_tuple
</span><span class=
"special">:
</span>
59 <span class=
"identifier">declaration
</span><span class=
"special">,
</span> <span class=
"identifier">declaration
</span><span class=
"special">,
</span> <span class=
"special">...
</span>
60 <span class=
"identifier">declaration_sequence
</span><span class=
"special">:
</span>
61 <span class=
"special">(
</span><span class=
"identifier">declaration
</span><span class=
"special">)
</span> <span class=
"special">(
</span><span class=
"identifier">declaration
</span><span class=
"special">)
</span> <span class=
"special">...
</span>
62 <span class=
"identifier">declaration
</span><span class=
"special">:
</span>
63 <span class=
"identifier">bound_variable
</span> <span class=
"special">|
</span> <span class=
"identifier">parameter
</span> <span class=
"special">|
</span> <span class=
"identifier">default_value
</span> <span class=
"special">|
</span> <span class=
"identifier">result_type
</span>
64 <span class=
"identifier">bound_variable
</span><span class=
"special">:
</span>
65 <span class=
"special">[
</span><span class=
"keyword">const
</span><span class=
"special">]
</span> <span class=
"identifier">bind
</span> <span class=
"special">[
</span><span class=
"special">(
</span><span class=
"identifier">variable_type
</span><span class=
"special">)
</span><span class=
"special">]
</span> <span class=
"special">[
</span><span class=
"special">&</span><span class=
"special">]
</span> <span class=
"identifier">variable_name
</span>
66 <span class=
"identifier">parameter
</span><span class=
"special">:
</span>
67 <span class=
"special">[
</span><span class=
"keyword">auto
</span> <span class=
"special">|
</span> <span class=
"keyword">register
</span><span class=
"special">]
</span> <span class=
"identifier">parameter_type
</span> <span class=
"identifier">parameter_name
</span>
68 <span class=
"identifier">default_value
</span><span class=
"special">:
</span>
69 <span class=
"keyword">default
</span> <span class=
"identifier">parameter_default_value
</span>
70 <span class=
"identifier">result_type
</span><span class=
"special">:
</span>
71 <span class=
"keyword">return
</span> <span class=
"identifier">function_result_type
</span>
72 </pre> On compilers that do not support variadic macros,
<code class=
"computeroutput">declaration_tuple
</code> cannot be used:
<pre xmlns:
rev=
"http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class=
"table-programlisting"><span class=
"identifier">declarations
</span><span class=
"special">:
</span>
73 <span class=
"keyword">void
</span> <span class=
"special">|
</span> <span class=
"identifier">declaration_sequence
</span>
74 </pre>(Lexical conventions:
<code class=
"computeroutput">token1 | token2
</code> means either
<code class=
"computeroutput">token1
</code> or
<code class=
"computeroutput">token2
</code>;
<code class=
"computeroutput">[token]
</code> means either
<code class=
"computeroutput">token
</code> or nothing;
<code class=
"computeroutput">{expression}
</code> means the token resulting from the expression.)
</td>
79 <p>Note that on compilers that support variadic macros, commas can be used to separate the declarations resembling more closely the usual C++ function declaration syntax (this is the preferred syntax). However, for portability, on all C++ compilers (with and without variadic macros) the same library macros also accept parameter declarations specified as a Boost.Preprocessor sequence separated by round parenthesis
<code class=
"computeroutput">()
</code>.
</p>
80 <p>When binding the object
<code class=
"computeroutput">this
</code>, the special symbol
<code class=
"computeroutput">this_
</code> needs to be used instead of
<code class=
"computeroutput">this
</code> as the name of the variable to bind and also within the local function body to access the object. (Mistakenly using
<code class=
"computeroutput">this
</code> instead of
<code class=
"computeroutput">this_
</code> might not always result in a compiler error and will in general result in undefined behaviour.)
</p>
81 <p>The result type must either be specified just before the macro or within the macro declarations prefixed by
<code class=
"computeroutput">return
</code> (but not in both places).
</p>
82 <p>Within the local function body it possible to access the result type using
<code class=
"computeroutput">result_type
</code>, the type of the first parameter using
<code class=
"computeroutput">arg1_type
</code>, the type of the second parameter using
<code class=
"computeroutput">arg2_type
</code>, etc. The bound variable types can be accessed using
<code class=
"computeroutput"><a class=
"link" href=
"BOOST_LOCAL_FUNCTION_TYPEOF.html" title=
"Macro BOOST_LOCAL_FUNCTION_TYPEOF">BOOST_LOCAL_FUNCTION_TYPEOF
</a></code>.
</p>
83 <p>This macro cannot be portably expanded multiple times on the same line. In these cases, use the
<code class=
"computeroutput"><a class=
"link" href=
"BOOST_LOCAL_FUNCTION_ID.html" title=
"Macro BOOST_LOCAL_FUNCTION_ID">BOOST_LOCAL_FUNCTION_ID
</a></code> macro instead.
</p>
84 <p>The maximum number of local function parameters (excluding bound variables) is specified by the configuration macro
<code class=
"computeroutput"><a class=
"link" href=
"BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX.html" title=
"Macro BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX">BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX
</a></code>. The maximum number of bound variables is specified by the configuration macro
<code class=
"computeroutput"><a class=
"link" href=
"BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX.html" title=
"Macro BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX">BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX
</a></code>. The configuration macro
<code class=
"computeroutput"><a class=
"link" href=
"BOOST_LOCAL_FUNCTION_CONFIG_LOCALS_AS_TPARAMS.html" title=
"Macro BOOST_LOCAL_FUNCTION_CONFIG_LOCALS_AS_TPARAMS">BOOST_LOCAL_FUNCTION_CONFIG_LOCALS_AS_TPARAMS
</a></code> can be used to force optimizations that reduce the local function call run-time overhead.
</p>
85 <p><span class=
"bold"><strong>Note:
</strong></span> Local functions are functors so they can be assigned to other functors like
<code class=
"computeroutput">boost::function
</code> (see Boost.Function).
</p>
86 <p><span class=
"bold"><strong>See:
</strong></span> <a class=
"link" href=
"boost_localfunction/tutorial.html" title=
"Tutorial"> Tutorial
</a> section,
<a class=
"link" href=
"boost_localfunction/advanced_topics.html" title=
"Advanced Topics"> Advanced Topics
</a> section,
<code class=
"computeroutput"><a class=
"link" href=
"BOOST_LOCAL_FUNCTION_NAME.html" title=
"Macro BOOST_LOCAL_FUNCTION_NAME">BOOST_LOCAL_FUNCTION_NAME
</a></code>,
<code class=
"computeroutput"><a class=
"link" href=
"BOOST_LOCAL_FUNCTION_TPL.html" title=
"Macro BOOST_LOCAL_FUNCTION_TPL">BOOST_LOCAL_FUNCTION_TPL
</a></code>,
<code class=
"computeroutput"><a class=
"link" href=
"BOOST_LOCAL_FUNCTION_NAME_TPL.html" title=
"Macro BOOST_LOCAL_FUNCTION_NAME_TPL">BOOST_LOCAL_FUNCTION_NAME_TPL
</a></code>,
<code class=
"computeroutput"><a class=
"link" href=
"BOOST_LOCAL_FUNCTION_TYPEOF.html" title=
"Macro BOOST_LOCAL_FUNCTION_TYPEOF">BOOST_LOCAL_FUNCTION_TYPEOF
</a></code>,
<code class=
"computeroutput"><a class=
"link" href=
"BOOST_LOCAL_FUNCTION_ID.html" title=
"Macro BOOST_LOCAL_FUNCTION_ID">BOOST_LOCAL_FUNCTION_ID
</a></code>,
<code class=
"computeroutput"><a class=
"link" href=
"BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX.html" title=
"Macro BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX">BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX
</a></code>,
<code class=
"computeroutput"><a class=
"link" href=
"BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX.html" title=
"Macro BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX">BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX
</a></code>,
<code class=
"computeroutput"><a class=
"link" href=
"BOOST_LOCAL_FUNCTION_CONFIG_LOCALS_AS_TPARAMS.html" title=
"Macro BOOST_LOCAL_FUNCTION_CONFIG_LOCALS_AS_TPARAMS">BOOST_LOCAL_FUNCTION_CONFIG_LOCALS_AS_TPARAMS
</a></code>.
</p>
89 <table xmlns:
rev=
"http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width=
"100%"><tr>
90 <td align=
"left"></td>
91 <td align=
"right"><div class=
"copyright-footer">Copyright
© 2009-
2012 Lorenzo
93 Distributed under the Boost Software License, Version
1.0 (see accompanying
94 file LICENSE_1_0.txt or a copy at
<a href=
"http://www.boost.org/LICENSE_1_0.txt" target=
"_top">http://www.boost.org/LICENSE_1_0.txt
</a>)
99 <div class=
"spirit-nav">
100 <a accesskey=
"p" href=
"reference.html"><img src=
"../../../../doc/src/images/prev.png" alt=
"Prev"></a><a accesskey=
"u" href=
"reference.html#header.boost.local_function_hpp"><img src=
"../../../../doc/src/images/up.png" alt=
"Up"></a><a accesskey=
"h" href=
"index.html"><img src=
"../../../../doc/src/images/home.png" alt=
"Home"></a><a accesskey=
"n" href=
"BOOST_LOCAL_FUNCTION_TPL.html"><img src=
"../../../../doc/src/images/next.png" alt=
"Next"></a>