BOOST_LOCAL_FUNCTION.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <html>
  2. <head>
  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&#160;1.&#160;Boost.LocalFunction 1.0.0">
  8. <link rel="up" href="reference.html#header.boost.local_function_hpp" title="Header &lt;boost/local_function.hpp&gt;">
  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">
  11. </head>
  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>
  20. </tr></table>
  21. <hr>
  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>
  24. </div>
  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 &#8212; This macro is used to start a local function declaration. </p>
  30. </div>
  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: &lt;<a class="link" href="reference.html#header.boost.local_function_hpp" title="Header &lt;boost/local_function.hpp&gt;">boost/local_function.hpp</a>&gt;
  33. </span>BOOST_LOCAL_FUNCTION(declarations)</pre></div>
  34. <div class="refsect1">
  35. <a name="id903895"></a><h2>Description</h2>
  36. <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>
  37. <pre class="programlisting"><span class="special">{</span> <span class="comment">// Some declarative context.</span>
  38. <span class="special">...</span>
  39. <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>
  40. <span class="special">...</span> <span class="comment">// Body code.</span>
  41. <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>
  42. <span class="special">...</span>
  43. <span class="special">}</span>
  44. </pre>
  45. <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>
  46. <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>
  47. <p><span class="bold"><strong>Parameters:</strong></span> </p>
  48. <div class="informaltable"><table class="table">
  49. <colgroup>
  50. <col>
  51. <col>
  52. </colgroup>
  53. <tbody><tr>
  54. <td><span class="bold"><strong><code class="computeroutput">declarations</code></strong></span></td>
  55. <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>
  56. <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>
  57. <span class="identifier">declaration_tuple</span><span class="special">:</span>
  58. <span class="identifier">declaration</span><span class="special">,</span> <span class="identifier">declaration</span><span class="special">,</span> <span class="special">...</span>
  59. <span class="identifier">declaration_sequence</span><span class="special">:</span>
  60. <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>
  61. <span class="identifier">declaration</span><span class="special">:</span>
  62. <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>
  63. <span class="identifier">bound_variable</span><span class="special">:</span>
  64. <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">&amp;</span><span class="special">]</span> <span class="identifier">variable_name</span>
  65. <span class="identifier">parameter</span><span class="special">:</span>
  66. <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>
  67. <span class="identifier">default_value</span><span class="special">:</span>
  68. <span class="keyword">default</span> <span class="identifier">parameter_default_value</span>
  69. <span class="identifier">result_type</span><span class="special">:</span>
  70. <span class="keyword">return</span> <span class="identifier">function_result_type</span>
  71. </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>
  72. <span class="keyword">void</span> <span class="special">|</span> <span class="identifier">declaration_sequence</span>
  73. </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>
  74. </tr></tbody>
  75. </table></div>
  76. <p>
  77. </p>
  78. <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>
  79. <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>
  80. <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>
  81. <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>
  82. <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>
  83. <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>
  84. <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>
  85. <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>
  86. </div>
  87. </div>
  88. <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
  89. <td align="left"></td>
  90. <td align="right"><div class="copyright-footer">Copyright &#169; 2009-2012 Lorenzo
  91. Caminiti<p>
  92. Distributed under the Boost Software License, Version 1.0 (see accompanying
  93. 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>)
  94. </p>
  95. </div></td>
  96. </tr></table>
  97. <hr>
  98. <div class="spirit-nav">
  99. <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>
  100. </div>
  101. </body>
  102. </html>