[DEV] add v1.76.0

This commit is contained in:
2021-10-05 21:37:46 +02:00
parent a97e9ae7d4
commit d0115b733d
45133 changed files with 4744437 additions and 1026325 deletions

227
doc/html/function/faq.html Normal file
View File

@@ -0,0 +1,227 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Frequently Asked Questions</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../function.html" title="Chapter 16. Boost.Function">
<link rel="prev" href="../boost/function_equal.html" title="Function template function_equal">
<link rel="next" href="misc.html" title="Miscellaneous 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"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../boost/function_equal.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../function.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="misc.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="function.faq"></a>Frequently Asked Questions</h2></div></div></div>
<div class="qandaset">
<a name="id-1.3.17.7.2"></a><dl>
<dt>1. <a href="faq.html#id-1.3.17.7.2.1">Why can't I compare
boost::function objects with
operator== or
operator!=?</a>
</dt>
<dt>2. <a href="faq.html#id-1.3.17.7.2.2">I see void pointers; is this [mess] type safe?</a>
</dt>
<dt>3. <a href="faq.html#id-1.3.17.7.2.3">Why are there workarounds for void returns? C++ allows them!</a>
</dt>
<dt>4. <a href="faq.html#id-1.3.17.7.2.4">Why (function) cloning?</a>
</dt>
<dt>5. <a href="faq.html#id-1.3.17.7.2.5">How much overhead does a call through boost::function incur?</a>
</dt>
</dl>
<table border="0" style="width: 100%;">
<colgroup>
<col align="left" width="1%">
<col>
</colgroup>
<tbody>
<tr class="question">
<td align="left" valign="top">
<a name="id-1.3.17.7.2.1"></a><a name="id-1.3.17.7.2.1.1"></a><p><b>1.</b></p>
</td>
<td align="left" valign="top"><p>Why can't I compare
<code class="computeroutput"><a class="link" href="../boost/function.html" title="Class template function">boost::function</a></code> objects with
<code class="computeroutput">operator==</code> or
<code class="computeroutput">operator!=</code>?</p></td>
</tr>
<tr class="answer">
<td align="left" valign="top"></td>
<td align="left" valign="top">
<p>Comparison between <code class="computeroutput"><a class="link" href="../boost/function.html" title="Class template function">boost::function</a></code>
objects cannot be implemented "well", and therefore will not be
implemented. The typical semantics requested for <code class="computeroutput">f ==
g</code> given <code class="computeroutput"><a class="link" href="../boost/function.html" title="Class template function">boost::function</a></code> objects
<code class="computeroutput">f</code> and <code class="computeroutput">g</code> are:</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">If <code class="computeroutput">f</code> and <code class="computeroutput">g</code>
store function objects of the same type, use that type's
<code class="computeroutput">operator==</code> to compare
them.</li>
<li class="listitem">If <code class="computeroutput">f</code> and <code class="computeroutput">g</code>
store function objects of different types, return
<code class="computeroutput">false</code>.</li>
</ul></div>
<p>The problem occurs when the type of the function objects
stored by both <code class="computeroutput">f</code> and <code class="computeroutput">g</code> doesn't have an
<code class="computeroutput">operator==</code>: we would like the expression <code class="computeroutput">f ==
g</code> to fail to compile, as occurs with, e.g., the standard
containers. However, this is not implementable for
<code class="computeroutput"><a class="link" href="../boost/function.html" title="Class template function">boost::function</a></code> because it necessarily
"erases" some type information after it has been assigned a
function object, so it cannot try to call
<code class="computeroutput">operator==</code> later: it must either find a way to call
<code class="computeroutput">operator==</code> now, or it will never be able to call it
later. Note, for instance, what happens if you try to put a
<code class="computeroutput">float</code> value into a
<code class="computeroutput"><a class="link" href="../boost/function.html" title="Class template function">boost::function</a></code> object: you will get an
error at the assignment operator or constructor, not in
<code class="computeroutput">operator()</code>, because the function-call expression
must be bound in the constructor or assignment operator.</p>
<p>The most promising approach is to find a method of
determining if <code class="computeroutput">operator==</code> can be called for a
particular type, and then supporting it only when it is
available; in other situations, an exception would be
thrown. However, to date there is no known way to detect if an
arbitrary operator expression <code class="computeroutput">f == g</code> is suitably
defined. The best solution known has the following undesirable
qualities:</p>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">Fails at compile-time for objects where
<code class="computeroutput">operator==</code> is not accessible (e.g., because it is
<code class="computeroutput">private</code>).</li>
<li class="listitem">Fails at compile-time if calling
<code class="computeroutput">operator==</code> is ambiguous.</li>
<li class="listitem">Appears to be correct if the
<code class="computeroutput">operator==</code> declaration is correct, even though
<code class="computeroutput">operator==</code> may not compile.</li>
</ol></div>
<p>All of these problems translate into failures in the
<code class="computeroutput"><a class="link" href="../boost/function.html" title="Class template function">boost::function</a></code> constructors or
assignment operator, <span class="emphasis"><em>even if the user never invokes
operator==</em></span>. We can't do that to users.</p>
<p>The other option is to place the burden on users that want
to use <code class="computeroutput">operator==</code>, e.g., by providing an
<code class="computeroutput">is_equality_comparable</code> trait they may
specialize. This is a workable solution, but is dangerous in
practice, because forgetting to specialize the trait will result
in unexpected exceptions being thrown from
<code class="computeroutput"><a class="link" href="../boost/function.html" title="Class template function">boost::function</a></code>'s
<code class="computeroutput">operator==</code>. This essentially negates the usefulness
of <code class="computeroutput">operator==</code> in the context in which it is most
desired: multitarget callbacks. The
Signals library has a way around
this.</p>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="id-1.3.17.7.2.2"></a><a name="id-1.3.17.7.2.2.1"></a><p><b>2.</b></p>
</td>
<td align="left" valign="top"><p>I see void pointers; is this [mess] type safe?</p></td>
</tr>
<tr class="answer">
<td align="left" valign="top"></td>
<td align="left" valign="top"><p>Yes, <code class="computeroutput">boost::function</code> is type
safe even though it uses void pointers and pointers to functions
returning void and taking no arguments. Essentially, all type
information is encoded in the functions that manage and invoke
function pointers and function objects. Only these functions are
instantiated with the exact type that is pointed to by the void
pointer or pointer to void function. The reason that both are required
is that one may cast between void pointers and object pointers safely
or between different types of function pointers (provided you don't
invoke a function pointer with the wrong type). </p></td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="id-1.3.17.7.2.3"></a><a name="id-1.3.17.7.2.3.1"></a><p><b>3.</b></p>
</td>
<td align="left" valign="top"><p>Why are there workarounds for void returns? C++ allows them!</p></td>
</tr>
<tr class="answer">
<td align="left" valign="top"></td>
<td align="left" valign="top">
<p>Void returns are permitted by the C++ standard, as in this code snippet:
</p>
<pre class="programlisting">void f();
void g() { return f(); }</pre>
<p>
</p>
<p> This is a valid usage of <code class="computeroutput">boost::function</code> because void returns are not used. With void returns, we would attempting to compile ill-formed code similar to:
</p>
<pre class="programlisting">int f();
void g() { return f(); }</pre>
<p>
</p>
<p> In essence, not using void returns allows
<code class="computeroutput">boost::function</code> to swallow a return value. This is
consistent with allowing the user to assign and invoke functions and
function objects with parameters that don't exactly match.</p>
</td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="id-1.3.17.7.2.4"></a><a name="id-1.3.17.7.2.4.1"></a><p><b>4.</b></p>
</td>
<td align="left" valign="top"><p>Why (function) cloning?</p></td>
</tr>
<tr class="answer">
<td align="left" valign="top"></td>
<td align="left" valign="top"><p>In November and December of 2000, the issue of cloning
vs. reference counting was debated at length and it was decided
that cloning gave more predictable semantics. I won't rehash the
discussion here, but if it cloning is incorrect for a particular
application a reference-counting allocator could be used.</p></td>
</tr>
<tr class="question">
<td align="left" valign="top">
<a name="id-1.3.17.7.2.5"></a><a name="id-1.3.17.7.2.5.1"></a><p><b>5.</b></p>
</td>
<td align="left" valign="top"><p>How much overhead does a call through <code class="computeroutput"><a class="link" href="../boost/function.html" title="Class template function">boost::function</a></code> incur?</p></td>
</tr>
<tr class="answer">
<td align="left" valign="top"></td>
<td align="left" valign="top">
<p>The cost of <code class="computeroutput">boost::function</code> can be reasonably
consistently measured at around 20ns +/- 10 ns on a modern &gt;2GHz
platform versus directly inlining the code.</p>
<p>However, the performance of your application may benefit
from or be disadvantaged by <code class="computeroutput">boost::function</code>
depending on how your C++ optimiser optimises. Similar to a
standard function pointer, differences of order of 10% have been
noted to the benefit or disadvantage of using
<code class="computeroutput">boost::function</code> to call a function that contains a
tight loop depending on your compilation circumstances.</p>
<p>[Answer provided by Matt Hurd. See <a href="http://article.gmane.org/gmane.comp.lib.boost.devel/33278" target="_top">http://article.gmane.org/gmane.comp.lib.boost.devel/33278</a>]</p>
</td>
</tr>
</tbody>
</table>
</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 © 2001-2004 Douglas Gregor<p>Use, modification and distribution is subject to the Boost
Software License, Version 1.0. (See accompanying file
<code class="filename">LICENSE_1_0.txt</code> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../boost/function_equal.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../function.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="misc.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,159 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>History &amp; Compatibility Notes</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../function.html" title="Chapter 16. Boost.Function">
<link rel="prev" href="../function.html" title="Chapter 16. Boost.Function">
<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"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../function.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../function.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="function.history"></a>History &amp; Compatibility Notes</h2></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist compact" style="list-style-type: disc; ">
<li class="listitem">
<p><span class="bold"><strong>Version 1.52.0</strong></span>: </p>
<div class="itemizedlist"><ul class="itemizedlist compact" style="list-style-type: circle; "><li class="listitem"><p>Move constructors and move assignment
operators added (only for compilers with C++11 rvalue
references support). Original patch
contributed by Antony Polukhin.</p></li></ul></div>
</li>
<li class="listitem">
<p><span class="bold"><strong>Version 1.37.0</strong></span>: </p>
<div class="itemizedlist"><ul class="itemizedlist compact" style="list-style-type: circle; ">
<li class="listitem"><p>Improved the performance of Boost.Function's
swap() operation for large function objects. Original patch
contributed by Niels Dekker.</p></li>
<li class="listitem"><p>Added a new header &lt;boost/function/function_typeof.hpp&gt; that provides support for using the Boost.Typeof library on Boost.Function objects.</p></li>
<li class="listitem"><p>Added a new header &lt;boost/function/function_fwd.hpp&gt; that provides support for using the Boost.Typeof library on Boost.Function objects.</p></li>
<li class="listitem"><p>The <code class="computeroutput"><a class="link" href="../boost/function.html#id-1_3_17_6_2_1_4_29_1-bb">target</a></code>()
function now respects the cv-qualifiers of function objects
stored by reference
(using <code class="computeroutput">boost::reference_wrapper</code>), such
that a reference to a <code class="computeroutput">const</code> function object cannot
be accessed as a reference to a non-<code class="computeroutput">const</code> function
object.</p></li>
</ul></div>
</li>
<li class="listitem">
<p><span class="bold"><strong>Version 1.36.0</strong></span>: </p>
<div class="itemizedlist"><ul class="itemizedlist compact" style="list-style-type: circle; "><li class="listitem"><p>Boost.Function now implements allocator support
in the same way that is is provided in C++0x, based on C++
committee
proposal <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2308.html" target="_top">N2308</a>. This
change removes the <code class="computeroutput">Allocator</code>
template parameter of <code class="computeroutput"><a class="link" href="../boost/function.html" title="Class template function">boost::function</a></code> in
favor of a constructor that takes an argument. While this is a
backward-incompatible change, it is likely to affect only a few
users. This change to Function was contributed by Emil
Dotchevski, which also authored the corresponding C++ committee
proposal.</p></li></ul></div>
</li>
<li class="listitem">
<p><span class="bold"><strong>Version 1.34.0</strong></span>: </p>
<div class="itemizedlist"><ul class="itemizedlist compact" style="list-style-type: circle; "><li class="listitem"><p>Boost.Function now implements a small buffer optimization, which can drastically improve the performance when copying or construction Boost.Function objects storing small function objects. For instance, <code class="computeroutput">bind(&amp;X:foo, &amp;x, _1, _2)</code> requires no heap allocation when placed into a Boost.Function object. Note that some exception-safety guarantees have changed: assignment provides the basic exception guarantee and <code class="computeroutput">swap()</code> may throw.</p></li></ul></div>
</li>
<li class="listitem">
<p><span class="bold"><strong>Version 1.30.0</strong></span>: </p>
<div class="itemizedlist"><ul class="itemizedlist compact" style="list-style-type: circle; ">
<li class="listitem"><p>All features deprecated in version 1.29.0 have
been removed from Boost.Function.</p></li>
<li class="listitem"><p><code class="computeroutput"><a class="link" href="../boost/function.html" title="Class template function">boost::function</a></code>
and <code class="computeroutput"><a class="link" href="../boost/functionN.html" title="Class template functionN">boost::functionN</a></code> objects
can be assigned to 0 (semantically equivalent to calling
<code class="computeroutput"><a class="link" href="../boost/function.html#id-1_3_17_6_2_1_4_27_2-bb">clear</a>()</code>) and
compared against 0 (semantically equivalent to calling
<code class="computeroutput"><a class="link" href="../boost/function.html#id-1_3_17_6_2_1_4_28_1-bb">empty</a>()</code>).</p></li>
<li class="listitem"><p>The Boost.Function code is now generated
entirely by the Preprocessor library,
so it is now possible to generate
<code class="computeroutput"><a class="link" href="../boost/function.html" title="Class template function">boost::function</a></code> and
<code class="computeroutput"><a class="link" href="../boost/functionN.html" title="Class template functionN">boost::functionN</a></code> class
templates for any number of arguments.</p></li>
<li class="listitem"><p>The
<code class="computeroutput"><a class="link" href="../boost/bad_function_call.html" title="Class bad_function_call">boost::bad_function_call</a></code> exception class
was introduced.</p></li>
</ul></div>
</li>
<li class="listitem">
<p><span class="bold"><strong>Version 1.29.0</strong></span>:
Boost.Function has been partially redesigned to minimize the
interface and make it cleaner. Several seldom- or never-used
features of the older Boost.Function have been deprecated and will
be removed in the near future. Here is a list of features that have
been deprecated, the likely impact of the deprecations, and how to
adjust your code:
</p>
<div class="itemizedlist"><ul class="itemizedlist compact" style="list-style-type: circle; ">
<li class="listitem">
<p>The <code class="computeroutput">boost::function</code> class template syntax has
changed. The old syntax, e.g., <code class="computeroutput">boost::function&lt;int, float,
double, std::string&gt;</code>, has been changed to a more natural
syntax <code class="computeroutput">boost::function&lt;int (float, double,
std::string)&gt;</code>, where all return and argument types are
encoded in a single function type parameter. Any other template
parameters (e.g., the <code class="computeroutput">Allocator</code>) follow this single
parameter.</p>
<p> The resolution to this change depends on the
abilities of your compiler: if your compiler supports template
partial specialization and can parse function types (most do), modify
your code to use the newer
syntax (preferable) or directly use one of the
<code class="computeroutput">functionN</code> classes whose syntax has not
changed. If your compiler does not support template partial
specialization or function types, you must take the latter option and
use the numbered Boost.Function classes. This option merely requires
changing types such as <code class="computeroutput">boost::function&lt;void, int, int&gt;</code>
to <code class="computeroutput">boost::function2&lt;void, int, int&gt;</code> (adding the number of
function arguments to the end of the class name).</p>
<p> Support for the old syntax with the
<code class="computeroutput">boost::function</code> class template will persist for a short
while, but will eventually be removed so that we can provide better
error messages and link compatibility. </p>
</li>
<li class="listitem"><p>The invocation
policy template parameter (<code class="computeroutput">Policy</code>) has been deprecated
and will be removed. There is no direct equivalent to this rarely
used feature.</p></li>
<li class="listitem"><p>The mixin template parameter
(<code class="computeroutput">Mixin</code>) has been deprecated and will be removed. There
is not direct equivalent to this rarely used feature.</p></li>
<li class="listitem"><p>The
<code class="computeroutput">set</code> methods have been deprecated and will be
removed. Use the assignment operator instead.</p></li>
</ul></div>
<p>
</p>
</li>
</ul></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 © 2001-2004 Douglas Gregor<p>Use, modification and distribution is subject to the Boost
Software License, Version 1.0. (See accompanying file
<code class="filename">LICENSE_1_0.txt</code> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../function.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../function.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>

112
doc/html/function/misc.html Normal file
View File

@@ -0,0 +1,112 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Miscellaneous Notes</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../function.html" title="Chapter 16. Boost.Function">
<link rel="prev" href="faq.html" title="Frequently Asked Questions">
<link rel="next" href="testsuite.html" title="Testsuite">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="faq.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../function.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="testsuite.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="function.misc"></a>Miscellaneous Notes</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="misc.html#id-1.3.17.8.2">Boost.Function vs. Function Pointers</a></span></dt>
<dt><span class="section"><a href="misc.html#id-1.3.17.8.3">Performance</a></span></dt>
<dt><span class="section"><a href="misc.html#id-1.3.17.8.4">Combatting virtual function "bloat"</a></span></dt>
<dt><span class="section"><a href="misc.html#id-1.3.17.8.5">Acknowledgements</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="id-1.3.17.8.2"></a>Boost.Function vs. Function Pointers</h3></div></div></div>
<p>Boost.Function has several advantages over function pointers, namely:
</p>
<div class="itemizedlist"><ul class="itemizedlist compact" style="list-style-type: disc; ">
<li class="listitem"><p>Boost.Function allows arbitrary compatible function objects to be targets (instead of requiring an exact function signature).</p></li>
<li class="listitem"><p>Boost.Function may be used with argument-binding and other function object construction libraries.</p></li>
<li class="listitem"><p>Boost.Function has predictible behavior when an empty function object is called. </p></li>
</ul></div>
<p> And, of course, function pointers have several advantages over Boost.Function:
</p>
<div class="itemizedlist"><ul class="itemizedlist compact" style="list-style-type: disc; ">
<li class="listitem"><p> Function pointers are smaller (the size of one pointer instead of four or more) </p></li>
<li class="listitem"><p> Function pointers are faster (Boost.Function may require two calls through function pointers) </p></li>
<li class="listitem"><p> Function pointers are backward-compatible with C libraries.</p></li>
<li class="listitem"><p> More readable error messages. </p></li>
</ul></div>
<p>
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="id-1.3.17.8.3"></a>Performance</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="misc.html#id-1.3.17.8.3.2">Function object wrapper size</a></span></dt>
<dt><span class="section"><a href="misc.html#id-1.3.17.8.3.3">Copying efficiency</a></span></dt>
<dt><span class="section"><a href="misc.html#id-1.3.17.8.3.4">Invocation efficiency</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="id-1.3.17.8.3.2"></a>Function object wrapper size</h4></div></div></div>
<p> Function object wrappers will be the size of a struct containing a member function pointer and two data pointers. The actual size can vary significantly depending on the underlying platform; on 32-bit Mac OS X with GCC, this amounts to 16 bytes, while it is 32 bytes Windows with Visual C++. Additionally, the function object target may be allocated on the heap, if it cannot be placed into the small-object buffer in the <code class="computeroutput">boost::function</code> object.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="id-1.3.17.8.3.3"></a>Copying efficiency</h4></div></div></div>
<p> Copying function object wrappers may require allocating memory for a copy of the function object target. The default allocator may be replaced with a faster custom allocator or one may choose to allow the function object wrappers to only store function object targets by reference (using <code class="computeroutput">ref</code>) if the cost of this cloning becomes prohibitive. Small function objects can be stored within the <code class="computeroutput">boost::function</code> object itself, improving copying efficiency.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="id-1.3.17.8.3.4"></a>Invocation efficiency</h4></div></div></div>
<p> With a properly inlining compiler, an invocation of a function object requires one call through a function pointer. If the call is to a free function pointer, an additional call must be made to that function pointer (unless the compiler has very powerful interprocedural analysis).</p>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="id-1.3.17.8.4"></a>Combatting virtual function "bloat"</h3></div></div></div>
<p> The use of virtual functions tends to cause 'code bloat' on many compilers. When a class contains a virtual function, it is necessary to emit an additional function that classifies the type of the object. It has been our experience that these auxiliary functions increase the size of the executable significantly when many <code class="computeroutput">boost::function</code> objects are used. </p>
<p> In Boost.Function, an alternative but equivalent approach was taken using free functions instead of virtual functions. The Boost.Function object essentially holds two pointers to make a valid target call: a void pointer to the function object it contains and a void pointer to an "invoker" that can call the function object, given the function pointer. This invoker function performs the argument and return value conversions Boost.Function provides. A third pointer points to a free function called the "manager", which handles the cloning and destruction of function objects. The scheme is typesafe because the only functions that actually handle the function object, the invoker and the manager, are instantiated given the type of the function object, so they can safely cast the incoming void pointer (the function object pointer) to the appropriate type.</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="id-1.3.17.8.5"></a>Acknowledgements</h3></div></div></div>
<p> Many people were involved in the construction of this
library. William Kempf, Jesse Jones and Karl Nelson were all
extremely helpful in isolating an interface and scope for the
library. John Maddock managed the formal review, and many
reviewers gave excellent comments on interface, implementation,
and documentation. Peter Dimov led us to the function
declarator-based syntax.</p>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2001-2004 Douglas Gregor<p>Use, modification and distribution is subject to the Boost
Software License, Version 1.0. (See accompanying file
<code class="filename">LICENSE_1_0.txt</code> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="faq.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../function.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="testsuite.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,176 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Reference</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../function.html" title="Chapter 16. Boost.Function">
<link rel="prev" href="tutorial.html" title="Tutorial">
<link rel="next" href="../boost/bad_function_call.html" title="Class bad_function_call">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="tutorial.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../function.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="../boost/bad_function_call.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="function.reference"></a>Reference</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="reference.html#function.definitions">Definitions</a></span></dt>
<dt><span class="section"><a href="reference.html#header.boost.function_hpp">Header &lt;boost/function.hpp&gt;</a></span></dt>
<dt><span class="section"><a href="reference.html#header.boost.function_equal_hpp">Header &lt;boost/function_equal.hpp&gt;</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function.definitions"></a>Definitions</h3></div></div></div>
<p>
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p>A function object <code class="computeroutput">f</code> is
<span class="emphasis"><em>compatible</em></span> if for the given set of argument
types <code class="computeroutput">Arg1</code>,
<code class="computeroutput">Arg2</code>, ...,
<code class="computeroutput">ArgN</code> and a
return type <code class="computeroutput">ResultType</code>, the
appropriate following function is well-formed:
</p>
<pre class="programlisting">
<span class="emphasis"><em>// if ResultType is not <span class="bold"><strong>void</strong></span></em></span>
ResultType foo(Arg1 arg1, Arg2 arg2, ..., Arg<span class="emphasis"><em>N</em></span> arg<span class="emphasis"><em>N</em></span>)
{
<span class="bold"><strong>return</strong></span> f(arg1, arg2, ..., arg<span class="emphasis"><em>N</em></span>);
}
<span class="emphasis"><em>// if ResultType is <span class="bold"><strong>void</strong></span></em></span>
ResultType foo(Arg1 arg1, Arg2 arg2, ..., Arg<span class="emphasis"><em>N</em></span> arg<span class="emphasis"><em>N</em></span>)
{
f(arg1, arg2, ..., arg<span class="emphasis"><em>N</em></span>);
}
</pre>
<p> A special provision is made for pointers to member
functions. Though they are not function objects, Boost.Function
will adapt them internally to function objects. This requires
that a pointer to member function of the form <code class="computeroutput">R
(X::*mf)(Arg1, Arg2, ..., ArgN)
cv-quals</code> be adapted to a
function object with the following function call operator
overloads:
</p>
<pre class="programlisting">
<span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename P</strong></span>&gt;
R <span class="bold"><strong>operator</strong></span>()(<span class="emphasis"><em>cv-quals</em></span> P&amp; x, Arg1 arg1, Arg2 arg2, ..., Arg<span class="emphasis"><em>N</em></span> arg<span class="emphasis"><em>N</em></span>) <span class="bold"><strong>const</strong></span>
{
<span class="bold"><strong>return</strong></span> (*x).*mf(arg1, arg2, ..., arg<span class="emphasis"><em>N</em></span>);
}
</pre>
<p>
</p>
</li>
<li class="listitem"><p>A function object <code class="computeroutput">f</code> of
type <code class="computeroutput">F</code> is
<span class="emphasis"><em>stateless</em></span> if it is a function pointer or if
<code class="computeroutput">boost::is_stateless&lt;F&gt;</code>
is true. The construction of or copy to a Boost.Function object
from a stateless function object will not cause exceptions to be
thrown and will not allocate any storage.
</p></li>
</ul></div>
<p>
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="header.boost.function_hpp"></a>Header &lt;<a href="../../../boost/function.hpp" target="_top">boost/function.hpp</a>&gt;</h3></div></div></div>
<pre class="synopsis"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>
<span class="keyword">class</span> <a class="link" href="../boost/bad_function_call.html" title="Class bad_function_call">bad_function_call</a><span class="special">;</span>
<span class="keyword">class</span> <a class="link" href="../boost/function_base.html" title="Class function_base">function_base</a><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> R<span class="special">,</span> <span class="keyword">typename</span> T1<span class="special">,</span> <span class="keyword">typename</span> T2<span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="keyword">typename</span> TN<span class="special">&gt;</span>
<span class="keyword">class</span> <a class="link" href="../boost/functionN.html" title="Class template functionN">functionN</a><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T1<span class="special">,</span> <span class="keyword">typename</span> T2<span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="keyword">typename</span> TN<span class="special">&gt;</span>
<span class="keyword">void</span> <a class="link" href="../boost/functionN.html#boost.functionN.swap"><span class="identifier">swap</span></a><span class="special">(</span><a class="link" href="../boost/functionN.html" title="Class template functionN">functionN</a><span class="special">&lt;</span><span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span><span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="identifier">TN</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">,</span> <a class="link" href="../boost/functionN.html" title="Class template functionN">functionN</a><span class="special">&lt;</span><span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span><span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="identifier">TN</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T1<span class="special">,</span> <span class="keyword">typename</span> T2<span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="keyword">typename</span> TN<span class="special">,</span> <span class="keyword">typename</span> Functor<span class="special">&gt;</span>
<span class="keyword">bool</span> <a class="link" href="../boost/functionN.html#id-1_3_17_6_2_1_3_28_1_1-bb"><span class="keyword">operator</span><span class="special">==</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="../boost/functionN.html" title="Class template functionN">functionN</a><span class="special">&lt;</span><span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span><span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="identifier">TN</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">,</span> <span class="identifier">Functor</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T1<span class="special">,</span> <span class="keyword">typename</span> T2<span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="keyword">typename</span> TN<span class="special">,</span> <span class="keyword">typename</span> Functor<span class="special">&gt;</span>
<span class="keyword">bool</span> <a class="link" href="../boost/functionN.html#id-1_3_17_6_2_1_3_28_1_2-bb"><span class="keyword">operator</span><span class="special">==</span></a><span class="special">(</span><span class="identifier">Functor</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../boost/functionN.html" title="Class template functionN">functionN</a><span class="special">&lt;</span><span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span><span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="identifier">TN</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T1<span class="special">,</span> <span class="keyword">typename</span> T2<span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="keyword">typename</span> TN<span class="special">,</span> <span class="keyword">typename</span> Functor<span class="special">&gt;</span>
<span class="keyword">bool</span> <a class="link" href="../boost/functionN.html#id-1_3_17_6_2_1_3_28_1_3-bb"><span class="keyword">operator</span><span class="special">==</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="../boost/functionN.html" title="Class template functionN">functionN</a><span class="special">&lt;</span><span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span><span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="identifier">TN</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">,</span>
reference_wrapper<span class="special">&lt;</span><span class="identifier">Functor</span><span class="special">&gt;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T1<span class="special">,</span> <span class="keyword">typename</span> T2<span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="keyword">typename</span> TN<span class="special">,</span> <span class="keyword">typename</span> Functor<span class="special">&gt;</span>
<span class="keyword">bool</span> <a class="link" href="../boost/functionN.html#id-1_3_17_6_2_1_3_28_1_4-bb"><span class="keyword">operator</span><span class="special">==</span></a><span class="special">(</span>reference_wrapper<span class="special">&lt;</span><span class="identifier">Functor</span><span class="special">&gt;</span><span class="special">,</span>
<span class="keyword">const</span> <a class="link" href="../boost/functionN.html" title="Class template functionN">functionN</a><span class="special">&lt;</span><span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span><span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="identifier">TN</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T1<span class="special">,</span> <span class="keyword">typename</span> T2<span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="keyword">typename</span> TN<span class="special">,</span> <span class="keyword">typename</span> U1<span class="special">,</span>
<span class="keyword">typename</span> U2<span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="keyword">typename</span> UN<span class="special">&gt;</span>
<span class="keyword">void</span> <a class="link" href="../boost/functionN.html#id-1_3_17_6_2_1_3_28_1_5-bb"><span class="keyword">operator</span><span class="special">==</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="../boost/functionN.html" title="Class template functionN">functionN</a><span class="special">&lt;</span><span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span><span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="identifier">TN</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">,</span>
<span class="keyword">const</span> <a class="link" href="../boost/functionN.html" title="Class template functionN">functionN</a><span class="special">&lt;</span><span class="identifier">U1</span><span class="special">,</span> <span class="identifier">U2</span><span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="identifier">UN</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T1<span class="special">,</span> <span class="keyword">typename</span> T2<span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="keyword">typename</span> TN<span class="special">,</span> <span class="keyword">typename</span> Functor<span class="special">&gt;</span>
<span class="keyword">bool</span> <a class="link" href="../boost/functionN.html#id-1_3_17_6_2_1_3_28_2_1-bb"><span class="keyword">operator</span><span class="special">!=</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="../boost/functionN.html" title="Class template functionN">functionN</a><span class="special">&lt;</span><span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span><span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="identifier">TN</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">,</span> <span class="identifier">Functor</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T1<span class="special">,</span> <span class="keyword">typename</span> T2<span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="keyword">typename</span> TN<span class="special">,</span> <span class="keyword">typename</span> Functor<span class="special">&gt;</span>
<span class="keyword">bool</span> <a class="link" href="../boost/functionN.html#id-1_3_17_6_2_1_3_28_2_2-bb"><span class="keyword">operator</span><span class="special">!=</span></a><span class="special">(</span><span class="identifier">Functor</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../boost/functionN.html" title="Class template functionN">functionN</a><span class="special">&lt;</span><span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span><span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="identifier">TN</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T1<span class="special">,</span> <span class="keyword">typename</span> T2<span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="keyword">typename</span> TN<span class="special">,</span> <span class="keyword">typename</span> Functor<span class="special">&gt;</span>
<span class="keyword">bool</span> <a class="link" href="../boost/functionN.html#id-1_3_17_6_2_1_3_28_2_3-bb"><span class="keyword">operator</span><span class="special">!=</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="../boost/functionN.html" title="Class template functionN">functionN</a><span class="special">&lt;</span><span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span><span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="identifier">TN</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">,</span>
reference_wrapper<span class="special">&lt;</span><span class="identifier">Functor</span><span class="special">&gt;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T1<span class="special">,</span> <span class="keyword">typename</span> T2<span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="keyword">typename</span> TN<span class="special">,</span> <span class="keyword">typename</span> Functor<span class="special">&gt;</span>
<span class="keyword">bool</span> <a class="link" href="../boost/functionN.html#id-1_3_17_6_2_1_3_28_2_4-bb"><span class="keyword">operator</span><span class="special">!=</span></a><span class="special">(</span>reference_wrapper<span class="special">&lt;</span><span class="identifier">Functor</span><span class="special">&gt;</span><span class="special">,</span>
<span class="keyword">const</span> <a class="link" href="../boost/functionN.html" title="Class template functionN">functionN</a><span class="special">&lt;</span><span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span><span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="identifier">TN</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> T1<span class="special">,</span> <span class="keyword">typename</span> T2<span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="keyword">typename</span> TN<span class="special">,</span> <span class="keyword">typename</span> U1<span class="special">,</span>
<span class="keyword">typename</span> U2<span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="keyword">typename</span> UN<span class="special">&gt;</span>
<span class="keyword">void</span> <a class="link" href="../boost/functionN.html#id-1_3_17_6_2_1_3_28_2_5-bb"><span class="keyword">operator</span><span class="special">!=</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="../boost/functionN.html" title="Class template functionN">functionN</a><span class="special">&lt;</span><span class="identifier">T1</span><span class="special">,</span> <span class="identifier">T2</span><span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="identifier">TN</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">,</span>
<span class="keyword">const</span> <a class="link" href="../boost/functionN.html" title="Class template functionN">functionN</a><span class="special">&lt;</span><span class="identifier">U1</span><span class="special">,</span> <span class="identifier">U2</span><span class="special">,</span> <span class="special">...</span><span class="special">,</span> <span class="identifier">UN</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Signature<span class="special">&gt;</span> <span class="keyword">class</span> <a class="link" href="../boost/function.html" title="Class template function">function</a><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Signature<span class="special">&gt;</span>
<span class="keyword">void</span> <a class="link" href="../boost/function.html#boost.function.swap"><span class="identifier">swap</span></a><span class="special">(</span><a class="link" href="../boost/function.html" title="Class template function">function</a><span class="special">&lt;</span><span class="identifier">Signature</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">,</span> <a class="link" href="../boost/function.html" title="Class template function">function</a><span class="special">&lt;</span><span class="identifier">Signature</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Signature<span class="special">,</span> <span class="keyword">typename</span> Functor<span class="special">&gt;</span>
<span class="keyword">bool</span> <a class="link" href="../boost/function.html#id-1_3_17_6_2_1_4_32_1_1-bb"><span class="keyword">operator</span><span class="special">==</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="../boost/function.html" title="Class template function">function</a><span class="special">&lt;</span><span class="identifier">Signature</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">,</span> <span class="identifier">Functor</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Signature<span class="special">,</span> <span class="keyword">typename</span> Functor<span class="special">&gt;</span>
<span class="keyword">bool</span> <a class="link" href="../boost/function.html#id-1_3_17_6_2_1_4_32_1_2-bb"><span class="keyword">operator</span><span class="special">==</span></a><span class="special">(</span><span class="identifier">Functor</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../boost/function.html" title="Class template function">function</a><span class="special">&lt;</span><span class="identifier">Signature</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Signature<span class="special">,</span> <span class="keyword">typename</span> Functor<span class="special">&gt;</span>
<span class="keyword">bool</span> <a class="link" href="../boost/function.html#id-1_3_17_6_2_1_4_32_1_3-bb"><span class="keyword">operator</span><span class="special">==</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="../boost/function.html" title="Class template function">function</a><span class="special">&lt;</span><span class="identifier">Signature</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">,</span> reference_wrapper<span class="special">&lt;</span><span class="identifier">Functor</span><span class="special">&gt;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Signature<span class="special">,</span> <span class="keyword">typename</span> Functor<span class="special">&gt;</span>
<span class="keyword">bool</span> <a class="link" href="../boost/function.html#id-1_3_17_6_2_1_4_32_1_4-bb"><span class="keyword">operator</span><span class="special">==</span></a><span class="special">(</span>reference_wrapper<span class="special">&lt;</span><span class="identifier">Functor</span><span class="special">&gt;</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../boost/function.html" title="Class template function">function</a><span class="special">&lt;</span><span class="identifier">Signature</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Signature1<span class="special">,</span> <span class="keyword">typename</span> Signature2<span class="special">&gt;</span>
<span class="keyword">void</span> <a class="link" href="../boost/function.html#id-1_3_17_6_2_1_4_32_1_5-bb"><span class="keyword">operator</span><span class="special">==</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="../boost/function.html" title="Class template function">function</a><span class="special">&lt;</span><span class="identifier">Signature1</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../boost/function.html" title="Class template function">function</a><span class="special">&lt;</span><span class="identifier">Signature2</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Signature<span class="special">,</span> <span class="keyword">typename</span> Functor<span class="special">&gt;</span>
<span class="keyword">bool</span> <a class="link" href="../boost/function.html#id-1_3_17_6_2_1_4_32_2_1-bb"><span class="keyword">operator</span><span class="special">!=</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="../boost/function.html" title="Class template function">function</a><span class="special">&lt;</span><span class="identifier">Signature</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">,</span> <span class="identifier">Functor</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Signature<span class="special">,</span> <span class="keyword">typename</span> Functor<span class="special">&gt;</span>
<span class="keyword">bool</span> <a class="link" href="../boost/function.html#id-1_3_17_6_2_1_4_32_2_2-bb"><span class="keyword">operator</span><span class="special">!=</span></a><span class="special">(</span><span class="identifier">Functor</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../boost/function.html" title="Class template function">function</a><span class="special">&lt;</span><span class="identifier">Signature</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Signature<span class="special">,</span> <span class="keyword">typename</span> Functor<span class="special">&gt;</span>
<span class="keyword">bool</span> <a class="link" href="../boost/function.html#id-1_3_17_6_2_1_4_32_2_3-bb"><span class="keyword">operator</span><span class="special">!=</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="../boost/function.html" title="Class template function">function</a><span class="special">&lt;</span><span class="identifier">Signature</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">,</span> reference_wrapper<span class="special">&lt;</span><span class="identifier">Functor</span><span class="special">&gt;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Signature<span class="special">,</span> <span class="keyword">typename</span> Functor<span class="special">&gt;</span>
<span class="keyword">bool</span> <a class="link" href="../boost/function.html#id-1_3_17_6_2_1_4_32_2_4-bb"><span class="keyword">operator</span><span class="special">!=</span></a><span class="special">(</span>reference_wrapper<span class="special">&lt;</span><span class="identifier">Functor</span><span class="special">&gt;</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../boost/function.html" title="Class template function">function</a><span class="special">&lt;</span><span class="identifier">Signature</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Signature1<span class="special">,</span> <span class="keyword">typename</span> Signature2<span class="special">&gt;</span>
<span class="keyword">void</span> <a class="link" href="../boost/function.html#id-1_3_17_6_2_1_4_32_2_5-bb"><span class="keyword">operator</span><span class="special">!=</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="../boost/function.html" title="Class template function">function</a><span class="special">&lt;</span><span class="identifier">Signature1</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="../boost/function.html" title="Class template function">function</a><span class="special">&lt;</span><span class="identifier">Signature2</span><span class="special">&gt;</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="special">}</span></pre>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="header.boost.function_equal_hpp"></a>Header &lt;<a href="../../../boost/function_equal.hpp" target="_top">boost/function_equal.hpp</a>&gt;</h3></div></div></div>
<pre class="synopsis"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> F<span class="special">,</span> <span class="keyword">typename</span> G<span class="special">&gt;</span> <span class="keyword">bool</span> <a class="link" href="../boost/function_equal.html" title="Function template function_equal"><span class="identifier">function_equal</span></a><span class="special">(</span><span class="keyword">const</span> <span class="identifier">F</span><span class="special">&amp;</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">G</span><span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="special">}</span></pre>
</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 © 2001-2004 Douglas Gregor<p>Use, modification and distribution is subject to the Boost
Software License, Version 1.0. (See accompanying file
<code class="filename">LICENSE_1_0.txt</code> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="tutorial.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../function.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="../boost/bad_function_call.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,200 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Testsuite</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../function.html" title="Chapter 16. Boost.Function">
<link rel="prev" href="misc.html" title="Miscellaneous Notes">
<link rel="next" href="../heap.html" title="Chapter 17. Boost.Heap">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="misc.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../function.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="../heap.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="function.testsuite"></a>Testsuite</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="testsuite.html#function.testsuite.acceptance">Acceptance tests</a></span></dt>
<dt><span class="section"><a href="testsuite.html#function.testsuite.negative">Negative tests</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function.testsuite.acceptance"></a>Acceptance tests</h3></div></div></div>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col width="1in">
<col>
</colgroup>
<thead><tr>
<th>Test</th>
<th>Type</th>
<th>Description</th>
<th>If failing...</th>
</tr></thead>
<tbody>
<tr>
<td><p><a href="../../../libs/function/test/function_test.cpp" target="_top">function_test.cpp</a></p></td>
<td><p>run</p></td>
<td><p>Test the capabilities of the <code class="computeroutput"><a class="link" href="../boost/function.html" title="Class template function">boost::function</a></code> class template.</p></td>
<td><p>The <code class="computeroutput"><a class="link" href="../boost/function.html" title="Class template function">boost::function</a></code> class template may not be usable on your compiler. However, the library may still be usable via the <code class="computeroutput"><a class="link" href="../boost/functionN.html" title="Class template functionN">boost::functionN</a></code> class templates.</p></td>
</tr>
<tr>
<td><p><a href="../../../libs/function/test/function_n_test.cpp" target="_top">function_n_test.cpp</a></p></td>
<td><p>run</p></td>
<td><p>Test the capabilities of the <code class="computeroutput"><a class="link" href="../boost/functionN.html" title="Class template functionN">boost::functionN</a></code> class templates.</p></td>
<td> </td>
</tr>
<tr>
<td><p><a href="../../../libs/function/test/allocator_test.cpp" target="_top">allocator_test.cpp</a></p></td>
<td><p>run</p></td>
<td><p>Test the use of custom allocators.</p></td>
<td><p>Allocators are ignored by the implementation.</p></td>
</tr>
<tr>
<td><p><a href="../../../libs/function/test/stateless_test.cpp" target="_top">stateless_test.cpp</a></p></td>
<td><p>run</p></td>
<td><p>Test the optimization of stateless function objects in the Boost.Function library.</p></td>
<td><p>The exception-safety and performance guarantees given for stateless function objects may not be met by the implementation.</p></td>
</tr>
<tr>
<td><p><a href="../../../libs/function/test/lambda_test.cpp" target="_top">lambda_test.cpp</a></p></td>
<td><p>run</p></td>
<td><p>Test the interaction between Boost.Function and Boost.Lambda.</p></td>
<td><p>Either Boost.Lambda does not work on the platform, or Boost.Function cannot safely be applied without the use of <code class="computeroutput">boost::unlambda</code>.</p></td>
</tr>
<tr>
<td><p><a href="../../../libs/function/test/contains_test.cpp" target="_top">contains_test.cpp</a></p></td>
<td><p>run</p></td>
<td><p>Test the operation of the
<code class="computeroutput">target</code> member function and the
equality operators.</p></td>
<td> </td>
</tr>
<tr>
<td><p><a href="../../../libs/function/test/function_30.cpp" target="_top">function_30.cpp</a></p></td>
<td><p>compile</p></td>
<td><p>Test the generation of a Boost.Function function object adaptor accepting 30 arguments.</p></td>
<td><p>The Boost.Function library may work for function object adaptors of up to 10 parameters, but will be unable to generate adaptors for an arbitrary number of parameters. Failure often indicates an error in the compiler's preprocessor.</p></td>
</tr>
<tr>
<td><p><a href="../../../libs/function/test/function_arith_cxx98.cpp" target="_top">function_arith_cxx98.cpp</a></p></td>
<td><p>run</p></td>
<td><p>Test the first tutorial example.</p></td>
<td> </td>
</tr>
<tr>
<td><p><a href="../../../libs/function/test/function_arith_portable.cpp" target="_top">function_arith_portable.cpp</a></p></td>
<td><p>run</p></td>
<td><p>Test the first tutorial example.</p></td>
<td> </td>
</tr>
<tr>
<td><p><a href="../../../libs/function/test/sum_avg_cxx98.cpp" target="_top">sum_avg_cxx98.cpp</a></p></td>
<td><p>run</p></td>
<td><p>Test the second tutorial example.</p></td>
<td> </td>
</tr>
<tr>
<td><p><a href="../../../libs/function/test/sum_avg_portable.cpp" target="_top">sum_avg_portable.cpp</a></p></td>
<td><p>run</p></td>
<td><p>Test the second tutorial example.</p></td>
<td> </td>
</tr>
<tr>
<td><p><a href="../../../libs/function/test/mem_fun_cxx98.cpp" target="_top">mem_fun_cxx98.cpp</a></p></td>
<td><p>run</p></td>
<td><p>Test member function example from tutorial.</p></td>
<td> </td>
</tr>
<tr>
<td><p><a href="../../../libs/function/test/mem_fun_portable.cpp" target="_top">mem_fun_portable.cpp</a></p></td>
<td><p>run</p></td>
<td><p>Test member function example from tutorial.</p></td>
<td> </td>
</tr>
<tr>
<td><p><a href="../../../libs/function/test/std_bind_cxx98.cpp" target="_top">std_bind_cxx98.cpp</a></p></td>
<td><p>run</p></td>
<td><p>Test standard binders example from tutorial.</p></td>
<td> </td>
</tr>
<tr>
<td><p><a href="../../../libs/function/test/std_bind_portable.cpp" target="_top">std_bind_portable.cpp</a></p></td>
<td><p>run</p></td>
<td><p>Test standard binders example from tutorial.</p></td>
<td> </td>
</tr>
<tr>
<td><p><a href="../../../libs/function/test/function_ref_cxx98.cpp" target="_top">function_ref_cxx98.cpp</a></p></td>
<td><p>run</p></td>
<td><p>Test <code class="computeroutput">boost::ref</code> example from tutorial.</p></td>
<td> </td>
</tr>
<tr>
<td><p><a href="../../../libs/function/test/function_ref_portable.cpp" target="_top">function_ref_portable.cpp</a></p></td>
<td><p>run</p></td>
<td><p>Test <code class="computeroutput">boost::ref</code> example from tutorial.</p></td>
<td> </td>
</tr>
</tbody>
</table></div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="function.testsuite.negative"></a>Negative tests</h3></div></div></div>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col width="1in">
<col>
</colgroup>
<thead><tr>
<th>Test</th>
<th>Type</th>
<th>Description</th>
<th>If failing...</th>
</tr></thead>
<tbody>
<tr>
<td><p><a href="../../../libs/function/test/function_test_fail1.cpp" target="_top">function_test_fail1.cpp</a></p></td>
<td><p>compile-fail</p></td>
<td><p>Test the (incorrect!) use of comparisons between Boost.Function function objects.</p></td>
<td><p>Intuitive (but incorrect!) code may compile and will give meaningless results.</p></td>
</tr>
<tr>
<td><p><a href="../../../libs/function/test/function_test_fail2.cpp" target="_top">function_test_fail2.cpp</a></p></td>
<td><p>compile-fail</p></td>
<td><p>Test the use of an incompatible function object with Boost.Function</p></td>
<td><p>Incorrect code may compile (with potentially unexpected results).</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 © 2001-2004 Douglas Gregor<p>Use, modification and distribution is subject to the Boost
Software License, Version 1.0. (See accompanying file
<code class="filename">LICENSE_1_0.txt</code> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="misc.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../function.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="../heap.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>

View File

@@ -0,0 +1,391 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Tutorial</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../function.html" title="Chapter 16. Boost.Function">
<link rel="prev" href="history.html" title="History &amp; Compatibility Notes">
<link rel="next" href="reference.html" title="Reference">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="history.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../function.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="reference.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="function.tutorial"></a>Tutorial</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="tutorial.html#id-1.3.17.5.4">Basic Usage</a></span></dt>
<dt><span class="section"><a href="tutorial.html#id-1.3.17.5.5">Free functions</a></span></dt>
<dt><span class="section"><a href="tutorial.html#id-1.3.17.5.6">Member functions</a></span></dt>
<dt><span class="section"><a href="tutorial.html#id-1.3.17.5.7">References to Function Objects</a></span></dt>
<dt><span class="section"><a href="tutorial.html#id-1.3.17.5.8">Comparing Boost.Function function objects</a></span></dt>
</dl></div>
<p> Boost.Function has two syntactical forms: the preferred form
and the portable form. The preferred form fits more closely with the
C++ language and reduces the number of separate template parameters
that need to be considered, often improving readability; however, the
preferred form is not supported on all platforms due to compiler
bugs. The compatible form will work on all compilers supported by
Boost.Function. Consult the table below to determine which syntactic
form to use for your compiler.
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th align="left">Preferred syntax</th>
<th align="left">Portable syntax</th>
</tr></thead>
<tbody><tr>
<td align="left">
<div class="itemizedlist"><ul class="itemizedlist compact" style="list-style-type: disc; ">
<li class="listitem">GNU C++ 2.95.x, 3.0.x and later versions</li>
<li class="listitem">Comeau C++ 4.2.45.2</li>
<li class="listitem">SGI MIPSpro 7.3.0</li>
<li class="listitem">Intel C++ 5.0, 6.0</li>
<li class="listitem">Compaq's cxx 6.2</li>
<li class="listitem">Microsoft Visual C++ 7.1 and later versions</li>
</ul></div>
</td>
<td align="left">
<div class="itemizedlist"><ul class="itemizedlist compact" style="list-style-type: disc; ">
<li class="listitem"><span class="emphasis"><em>Any compiler supporting the preferred syntax</em></span></li>
<li class="listitem">Microsoft Visual C++ 6.0, 7.0</li>
<li class="listitem">Borland C++ 5.5.1</li>
<li class="listitem">Sun WorkShop 6 update 2 C++ 5.3</li>
<li class="listitem">Metrowerks CodeWarrior 8.1</li>
</ul></div>
</td>
</tr></tbody>
</table></div>
<p>
</p>
<p> If your compiler does not appear in this list, please try the preferred syntax and report your results to the Boost list so that we can keep this table up-to-date.</p>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="id-1.3.17.5.4"></a>Basic Usage</h3></div></div></div>
<p> A function wrapper is defined simply
by instantiating the <code class="computeroutput">function</code> class
template with the desired return type and argument types, formulated
as a C++ function type. Any number of arguments may be supplied, up to
some implementation-defined limit (10 is the default maximum). The
following declares a function object wrapper
<code class="computeroutput">f</code> that takes two
<code class="computeroutput">int</code> parameters and returns a
<code class="computeroutput">float</code>:
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th align="left">Preferred syntax</th>
<th align="left">Portable syntax</th>
</tr></thead>
<tbody><tr>
<td align="left">
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><code class="computeroutput"><a class="link" href="../boost/function.html" title="Class template function">boost::function</a></code>&lt;float (int x, int y)&gt; f;</pre>
</td>
<td align="left">
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><code class="computeroutput"><a class="link" href="../boost/functionN.html" title="Class template functionN">boost::function2</a></code>&lt;float, int, int&gt; f;</pre>
</td>
</tr></tbody>
</table></div>
<p>
</p>
<p> By default, function object wrappers are empty, so we can create a
function object to assign to <code class="computeroutput">f</code>:
</p>
<pre class="programlisting">struct int_div {
float operator()(int x, int y) const { return ((float)x)/y; };
};</pre>
<p>
</p>
<pre class="programlisting">f = int_div();</pre>
<p>
</p>
<p> Now we can use <code class="computeroutput">f</code> to execute
the underlying function object
<code class="computeroutput">int_div</code>:
</p>
<pre class="programlisting">std::cout &lt;&lt; f(5, 3) &lt;&lt; std::endl;</pre>
<p>
</p>
<p> We are free to assign any compatible function object to
<code class="computeroutput">f</code>. If
<code class="computeroutput">int_div</code> had been declared to take two
<code class="computeroutput">long</code> operands, the implicit
conversions would have been applied to the arguments without any user
interference. The only limit on the types of arguments is that they be
CopyConstructible, so we can even use references and arrays:
</p>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th align="left">Preferred syntax</th></tr></thead>
<tbody><tr><td align="left">
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><code class="computeroutput"><a class="link" href="../boost/function.html" title="Class template function">boost::function</a></code>&lt;void (int values[], int n, int&amp; sum, float&amp; avg)&gt; sum_avg;</pre>
</td></tr></tbody>
</table></div>
<p>
</p>
<div class="informaltable"><table class="table">
<colgroup><col></colgroup>
<thead><tr><th align="left">Portable syntax</th></tr></thead>
<tbody><tr><td align="left">
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><code class="computeroutput"><a class="link" href="../boost/functionN.html" title="Class template functionN">boost::function4</a></code>&lt;void, int*, int, int&amp;, float&amp;&gt; sum_avg;</pre>
</td></tr></tbody>
</table></div>
<p>
</p>
<pre class="programlisting">void do_sum_avg(int values[], int n, int&amp; sum, float&amp; avg)
{
sum = 0;
for (int i = 0; i &lt; n; i++)
sum += values[i];
avg = (float)sum / n;
}</pre>
<p>
</p>
<pre class="programlisting">sum_avg = &amp;do_sum_avg;</pre>
<p>
</p>
<p> Invoking a function object wrapper that does not actually
contain a function object is a precondition violation, much like
trying to call through a null function pointer, and will throw a <code class="computeroutput"><a class="link" href="../boost/bad_function_call.html" title="Class bad_function_call">bad_function_call</a></code> exception). We can check for an
empty function object wrapper by using it in a boolean context (it evaluates <code class="computeroutput">true</code> if the wrapper is not empty) or compare it against <code class="computeroutput">0</code>. For instance:
</p>
<pre class="programlisting">if (f)
std::cout &lt;&lt; f(5, 3) &lt;&lt; std::endl;
else
std::cout &lt;&lt; "f has no target, so it is unsafe to call" &lt;&lt; std::endl;</pre>
<p>
</p>
<p> Alternatively,
<code class="computeroutput"><code class="computeroutput"><a class="link" href="../boost/function.html#id-1_3_17_6_2_1_4_28_1-bb">empty</a></code>()</code>
method will return whether or not the wrapper is empty. </p>
<p> Finally, we can clear out a function target by assigning it to <code class="computeroutput">0</code> or by calling the <code class="computeroutput"><code class="computeroutput"><a class="link" href="../boost/function.html#id-1_3_17_6_2_1_4_27_2-bb">clear</a></code>()</code> member function, e.g.,
</p>
<pre class="programlisting">f = 0;</pre>
<p>
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="id-1.3.17.5.5"></a>Free functions</h3></div></div></div>
<p> Free function pointers can be considered singleton function objects with const function call operators, and can therefore be directly used with the function object wrappers:
</p>
<pre class="programlisting">float mul_ints(int x, int y) { return ((float)x) * y; }</pre>
<p>
</p>
<pre class="programlisting">f = &amp;mul_ints;</pre>
<p>
</p>
<p> Note that the <code class="computeroutput">&amp;</code> isn't really necessary unless you happen to be using Microsoft Visual C++ version 6. </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="id-1.3.17.5.6"></a>Member functions</h3></div></div></div>
<p> In many systems, callbacks often call to member functions of a
particular object. This is often referred to as "argument binding",
and is beyond the scope of Boost.Function. The use of member functions
directly, however, is supported, so the following code is valid:
</p>
<pre class="programlisting">struct X {
int foo(int);
};</pre>
<p>
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th align="left">Preferred syntax</th>
<th align="left">Portable syntax</th>
</tr></thead>
<tbody><tr>
<td align="left">
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><code class="computeroutput"><a class="link" href="../boost/function.html" title="Class template function">boost::function</a></code>&lt;int (X*, int)&gt; f;
f = &amp;X::foo;
X x;
f(&amp;x, 5);</pre>
</td>
<td align="left">
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"><code class="computeroutput"><a class="link" href="../boost/functionN.html" title="Class template functionN">boost::function2</a></code>&lt;int, X*, int&gt; f;
f = &amp;X::foo;
X x;
f(&amp;x, 5);</pre>
</td>
</tr></tbody>
</table></div>
<p>
</p>
<p> Several libraries exist that support argument binding. Three such libraries are summarized below:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p>Bind. This library allows binding of
arguments for any function object. It is lightweight and very
portable.</p></li>
<li class="listitem">
<p>The C++ Standard library. Using
<code class="computeroutput">std::bind1st</code> and
<code class="computeroutput">std::mem_fun</code> together one can bind
the object of a pointer-to-member function for use with
Boost.Function:
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th align="left">Preferred syntax</th>
<th align="left">Portable syntax</th>
</tr></thead>
<tbody><tr>
<td align="left">
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"> <code class="computeroutput"><a class="link" href="../boost/function.html" title="Class template function">boost::function</a></code>&lt;int (int)&gt; f;
X x;
f = std::bind1st(
std::mem_fun(&amp;X::foo), &amp;x);
f(5); // Call x.foo(5)</pre>
</td>
<td align="left">
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting"> <code class="computeroutput"><a class="link" href="../boost/functionN.html" title="Class template functionN">boost::function1</a></code>&lt;int, int&gt; f;
X x;
f = std::bind1st(
std::mem_fun(&amp;X::foo), &amp;x);
f(5); // Call x.foo(5)</pre>
</td>
</tr></tbody>
</table></div>
<p>
</p>
</li>
<li class="listitem"><p>The <a class="link" href="../lambda.html" title="Chapter 20. Boost.Lambda">Lambda</a> library. This library provides a powerful composition mechanism to construct function objects that uses very natural C++ syntax. Lambda requires a compiler that is reasonably conformant to the C++ standard. </p></li>
</ul></div>
<p>
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="id-1.3.17.5.7"></a>References to Function Objects</h3></div></div></div>
<p> In some cases it is
expensive (or semantically incorrect) to have Boost.Function clone a
function object. In such cases, it is possible to request that
Boost.Function keep only a reference to the actual function
object. This is done using the <code class="computeroutput">ref</code>
and <code class="computeroutput">cref</code> functions to wrap a
reference to a function object:
</p>
<div class="informaltable"><table class="table">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th align="left">Preferred syntax</th>
<th align="left">Portable syntax</th>
</tr></thead>
<tbody><tr>
<td align="left">
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting">stateful_type a_function_object;
<code class="computeroutput"><a class="link" href="../boost/function.html" title="Class template function">boost::function</a></code>&lt;int (int)&gt; f;
f = <code class="computeroutput">boost::ref</code>(a_function_object);
<code class="computeroutput"><a class="link" href="../boost/function.html" title="Class template function">boost::function</a></code>&lt;int (int)&gt; f2(f);</pre>
</td>
<td align="left">
<pre xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="table-programlisting">stateful_type a_function_object;
<code class="computeroutput"><a class="link" href="../boost/functionN.html" title="Class template functionN">boost::function1</a></code>&lt;int, int&gt; f;
f = <code class="computeroutput">boost::ref</code>(a_function_object);
<code class="computeroutput"><a class="link" href="../boost/functionN.html" title="Class template functionN">boost::function1</a></code>&lt;int, int&gt; f2(f);</pre>
</td>
</tr></tbody>
</table></div>
<p>
</p>
<p> Here, <code class="computeroutput">f</code> will not make a copy
of <code class="computeroutput">a_function_object</code>, nor will
<code class="computeroutput">f2</code> when it is targeted to
<code class="computeroutput">f</code>'s reference to
<code class="computeroutput">a_function_object</code>. Additionally, when
using references to function objects, Boost.Function will not throw
exceptions during assignment or construction.
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="id-1.3.17.5.8"></a>Comparing Boost.Function function objects</h3></div></div></div>
<p>Function object wrappers can be compared via <code class="computeroutput">==</code>
or <code class="computeroutput">!=</code> against any function object that can be stored
within the wrapper. If the function object wrapper contains a
function object of that type, it will be compared against the given
function object (which must be either be
<a class="link" href="../EqualityComparable.html" title="Concept EqualityComparable">EqualityComparable</a> or have an overloaded <code class="computeroutput"><a class="link" href="../boost/function_equal.html" title="Function template function_equal">boost::function_equal</a></code>). For instance:</p>
<pre class="programlisting">int compute_with_X(X*, int);
f = &amp;X::foo;
assert(f == &amp;X::foo);
assert(&amp;compute_with_X != f);</pre>
<p>When comparing against an instance of
<code class="computeroutput">reference_wrapper</code>, the address
of the object in the
<code class="computeroutput">reference_wrapper</code> is compared
against the address of the object stored by the function object
wrapper:</p>
<pre class="programlisting">a_stateful_object so1, so2;
f = <code class="computeroutput">boost::ref</code>(so1);
assert(f == <code class="computeroutput">boost::ref</code>(so1));
assert(f == so1); <span class="emphasis"><em>// Only if a_stateful_object is <a class="link" href="../EqualityComparable.html" title="Concept EqualityComparable">EqualityComparable</a></em></span>
assert(f != <code class="computeroutput">boost::ref</code>(so2));</pre>
</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 © 2001-2004 Douglas Gregor<p>Use, modification and distribution is subject to the Boost
Software License, Version 1.0. (See accompanying file
<code class="filename">LICENSE_1_0.txt</code> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="history.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../function.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="reference.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>