Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/doc/html/boost/function.html @ 12

Last change on this file since 12 was 12, checked in by landauf, 18 years ago

added boost

File size: 40.7 KB
Line 
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
4<title>Class template function</title>
5<link rel="stylesheet" href="../boostbook.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
7<link rel="start" href="../index.html" title="The Boost C++ Libraries">
8<link rel="up" href="../function/reference.html#header.boost.function.hpp" title="Header &lt;boost/function.hpp&gt;">
9<link rel="prev" href="../functionN.html" title="Class template functionN">
10<link rel="next" href="../function_equal.html" title="Function template function_equal">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%">
14<td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../../boost.png"></td>
15<td align="center"><a href="../../../index.htm">Home</a></td>
16<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="../../../people/people.htm">People</a></td>
18<td align="center"><a href="../../../more/faq.htm">FAQ</a></td>
19<td align="center"><a href="../../../more/index.htm">More</a></td>
20</table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="../functionN.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function/reference.html#header.boost.function.hpp"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="../function_equal.html"><img src="../images/next.png" alt="Next"></a>
24</div>
25<div class="refentry" lang="en">
26<a name="boost.function"></a><div class="titlepage"></div>
27<div class="refnamediv">
28<h2><span class="refentrytitle">Class template function</span></h2>
29<p>boost::function &#8212; A generalized function pointer that can be used for
30    callbacks or wrapping function objects.</p>
31</div>
32<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
33<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Signature, <span class="emphasis"><em>  // Function type R (T1, T2, ..., TN)</em></span>
34         <span class="bold"><strong>typename</strong></span> Allocator = std::allocator&lt;<span class="bold"><strong>void</strong></span>&gt; &gt; 
35<span class="bold"><strong>class</strong></span> function : <span class="bold"><strong>public</strong></span> <a href="../functionN.html" title="Class template functionN">functionN</a>&lt;R, T1, T2, ..., TN, Allocator&gt; {
36<span class="bold"><strong>public</strong></span>:
37  <span class="emphasis"><em>// types</em></span>
38  <span class="bold"><strong>typedef</strong></span> R         result_type;         
39  <span class="bold"><strong>typedef</strong></span> Allocator allocator_type;      
40  <span class="bold"><strong>typedef</strong></span> T1        argument_type;         <span class="emphasis"><em>// If N == 1</em></span>
41  <span class="bold"><strong>typedef</strong></span> T1        first_argument_type;   <span class="emphasis"><em>// If N == 2</em></span>
42  <span class="bold"><strong>typedef</strong></span> T2        second_argument_type;  <span class="emphasis"><em>// If N == 2</em></span>
43  <span class="bold"><strong>typedef</strong></span> T1        arg1_type;           
44  <span class="bold"><strong>typedef</strong></span> T2        arg2_type;           
45     .
46     .
47     .
48  <span class="bold"><strong>typedef</strong></span> TN        argN_type;           
49
50  <span class="emphasis"><em>// static constants</em></span>
51  <span class="bold"><strong>static</strong></span> <span class="bold"><strong>const</strong></span> <span class="bold"><strong>int</strong></span> arity = N;
52
53  <span class="emphasis"><em>// <a href="../lambda.html" title="Chapter 6. Boost.Lambda">Lambda</a> library support</em></span>
54  <span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Args&gt; 
55  <span class="bold"><strong>struct</strong></span> sig {
56    <span class="emphasis"><em>// types</em></span>
57    <span class="bold"><strong>typedef</strong></span> result_type type;
58  };
59
60  <span class="emphasis"><em>// <a href="function.html#boost.functionconstruct-copy-destruct">construct/copy/destruct</a></em></span>
61  <a href="function.html#id2349250-bb">function</a>();
62  <a href="function.html#id2369646-bb">function</a>(<span class="bold"><strong>const</strong></span> <a href="../functionN.html" title="Class template functionN">functionN</a>&amp;);
63  <a href="function.html#id2339094-bb">function</a>(<span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&amp;);
64  <span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> F&gt; <a href="function.html#id2380764-bb">function</a>(F);
65  function&amp; <a href="function.html#id2350723-bb"><span class="bold"><strong>operator</strong></span>=</a>(<span class="bold"><strong>const</strong></span> <a href="../functionN.html" title="Class template functionN">functionN</a>&amp;);
66  function&amp; <a href="function.html#id2406303-bb"><span class="bold"><strong>operator</strong></span>=</a>(<span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&amp;);
67  <a href="function.html#id2360840-bb">~function</a>();
68
69  <span class="emphasis"><em>// <a href="function.html#id2342120-bb">modifiers</a></em></span>
70  <span class="type"><span class="bold"><strong>void</strong></span></span> <a href="function.html#id2342124-bb">swap</a>(<span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&amp;);
71  <span class="type"><span class="bold"><strong>void</strong></span></span> <a href="function.html#id2434373-bb">clear</a>();
72
73  <span class="emphasis"><em>// <a href="function.html#id2396338-bb">capacity</a></em></span>
74  <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="function.html#id2396343-bb">empty</a>() <span class="bold"><strong>const</strong></span>;
75  <a href="function.html#id2336149-bb"><span class="bold"><strong>operator</strong></span> safe_bool</a>() <span class="bold"><strong>const</strong></span>;
76  <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="function.html#id2371599-bb"><span class="bold"><strong>operator</strong></span>!</a>() <span class="bold"><strong>const</strong></span>;
77
78  <span class="emphasis"><em>// <a href="function.html#id2378753-bb">target access</a></em></span>
79  <span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Functor&gt; <span class="type">Functor*</span> <a href="function.html#id2378762-bb">target</a>();
80  <span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Functor&gt; <span class="type"><span class="bold"><strong>const</strong></span> Functor*</span> <a href="function.html#id2376534-bb">target</a>() <span class="bold"><strong>const</strong></span>;
81  <span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Functor&gt; <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="function.html#id2426358-bb">contains</a>(<span class="bold"><strong>const</strong></span> Functor&amp;) <span class="bold"><strong>const</strong></span>;
82
83  <span class="emphasis"><em>// <a href="function.html#id2404064-bb">invocation</a></em></span>
84  <span class="type">result_type</span> <a href="function.html#id2404069-bb"><span class="bold"><strong>operator</strong></span>()</a>(arg1_type, arg2_type, ..., argN_type) <span class="bold"><strong>const</strong></span>;
85};
86
87<span class="emphasis"><em>// <a href="function.html#id2408546-bb">specialized algorithms</a></em></span>
88<span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator&gt; 
89  <span class="type"><span class="bold"><strong>void</strong></span></span> <a href="function.html#id2408551">swap</a>(<a href="function.html" title="Class template function">function</a>&lt;Signature, Allocator&gt;&amp;, <a href="function.html" title="Class template function">function</a>&lt;Signature, Allocator&gt;&amp;);
90
91<span class="emphasis"><em>// <a href="function.html#id2420066-bb">comparison operators</a></em></span>
92<span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor&gt; 
93  <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="function.html#id2341297-bb"><span class="bold"><strong>operator</strong></span>==</a>(<span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&lt;Signature, Allocator&gt;&amp;, Functor);
94<span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor&gt; 
95  <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="function.html#id2399796-bb"><span class="bold"><strong>operator</strong></span>==</a>(Functor, <span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&lt;Signature, Allocator&gt;&amp;);
96<span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor&gt; 
97  <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="function.html#id2444136-bb"><span class="bold"><strong>operator</strong></span>==</a>(<span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&lt;Signature, Allocator&gt;&amp;,
98                  <a href="../reference_wrapper.html" title="Class template reference_wrapper">reference_wrapper</a>&lt;Functor&gt;);
99<span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor&gt; 
100  <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="function.html#id2477463-bb"><span class="bold"><strong>operator</strong></span>==</a>(<a href="../reference_wrapper.html" title="Class template reference_wrapper">reference_wrapper</a>&lt;Functor&gt;,
101                  <span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&lt;Signature, Allocator&gt;&amp;);
102<span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Signature1, <span class="bold"><strong>typename</strong></span> Allocator1, <span class="bold"><strong>typename</strong></span> Signature2,
103         <span class="bold"><strong>typename</strong></span> Allocator2&gt; 
104  <span class="type"><span class="bold"><strong>void</strong></span></span> <a href="function.html#id2378044-bb"><span class="bold"><strong>operator</strong></span>==</a>(<span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&lt;Signature1, Allocator1&gt;&amp;,
105                  <span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&lt;Signature2, Allocator2&gt;&amp;);
106<span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor&gt; 
107  <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="function.html#id2336228-bb"><span class="bold"><strong>operator</strong></span>!=</a>(<span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&lt;Signature, Allocator&gt;&amp;, Functor);
108<span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor&gt; 
109  <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="function.html#id2337224-bb"><span class="bold"><strong>operator</strong></span>!=</a>(Functor, <span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&lt;Signature, Allocator&gt;&amp;);
110<span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor&gt; 
111  <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="function.html#id2508816-bb"><span class="bold"><strong>operator</strong></span>!=</a>(<span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&lt;Signature, Allocator&gt;&amp;,
112                  <a href="../reference_wrapper.html" title="Class template reference_wrapper">reference_wrapper</a>&lt;Functor&gt;);
113<span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor&gt; 
114  <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="function.html#id2407103-bb"><span class="bold"><strong>operator</strong></span>!=</a>(<a href="../reference_wrapper.html" title="Class template reference_wrapper">reference_wrapper</a>&lt;Functor&gt;,
115                  <span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&lt;Signature, Allocator&gt;&amp;);
116<span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Signature1, <span class="bold"><strong>typename</strong></span> Allocator1, <span class="bold"><strong>typename</strong></span> Signature2,
117         <span class="bold"><strong>typename</strong></span> Allocator2&gt; 
118  <span class="type"><span class="bold"><strong>void</strong></span></span> <a href="function.html#id2469309-bb"><span class="bold"><strong>operator</strong></span>!=</a>(<span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&lt;Signature1, Allocator1&gt;&amp;,
119                  <span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&lt;Signature2, Allocator2&gt;&amp;);</pre></div>
120<div class="refsect1" lang="en">
121<a name="id2696608"></a><h2>Description</h2>
122<p>Class template <a href="function.html" title="Class template function">function</a> is a thin
123      wrapper around the numbered class templates <a href="../functionN.html" title="Class template functionN">function0</a>, <a href="../functionN.html" title="Class template functionN">function1</a>, etc. It accepts a
124      function type with N arguments and will will derive from
125      <a href="../functionN.html" title="Class template functionN">functionN</a> instantiated with the arguments
126      it receives.</p>
127<p>The semantics of all operations in class template
128      <a href="function.html" title="Class template function">function</a> are equivalent to that of the
129      underlying <a href="../functionN.html" title="Class template functionN">functionN</a> object, although
130      additional member functions are required to allow proper copy
131      construction and copy assignment of function objects.</p>
132<div class="refsect2" lang="en">
133<a name="id2696664"></a><h3>
134<a name="boost.functionconstruct-copy-destruct"></a><code class="computeroutput">function</code> construct/copy/destruct</h3>
135<div class="orderedlist"><ol type="1">
136<li>
137<pre class="literallayout"><a name="id2349250-bb"></a>function();</pre>
138<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Postconditions</span></b>:
139
140    <code class="computeroutput">this-&gt;<a href="function.html#id2396343-bb">empty</a>()</code><br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
141
142    Will not throw.</p>
143</li>
144<li>
145<pre class="literallayout"><a name="id2369646-bb"></a>function(<span class="bold"><strong>const</strong></span> <a href="../functionN.html" title="Class template functionN">functionN</a>&amp; f);</pre>
146<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Postconditions</span></b>:
147
148    Contains a copy of the <code class="computeroutput">f</code>'s target, if it has one, or is empty if <code class="computeroutput">f.<a href="function.html#id2396343-bb">empty</a>()</code>.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
149
150    Will not throw unless copying the target of <code class="computeroutput">f</code> throws.</p>
151</li>
152<li>
153<pre class="literallayout"><a name="id2339094-bb"></a>function(<span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&amp; f);</pre>
154<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Postconditions</span></b>:
155
156    Contains a copy of the <code class="computeroutput">f</code>'s target, if it has one, or is empty if <code class="computeroutput">f.<a href="function.html#id2396343-bb">empty</a>()</code>.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
157
158    Will not throw unless copying the target of <code class="computeroutput">f</code> throws.</p>
159</li>
160<li>
161<pre class="literallayout"><span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> F&gt; <a name="id2380764-bb"></a>function(F f);</pre>
162<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Requires</span></b>:
163
164    F is a function object Callable from <code class="computeroutput">this</code>.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Postconditions</span></b>:
165
166    <code class="computeroutput">*this</code> targets a copy of <code class="computeroutput">f</code> if <code class="computeroutput">f</code> is nonempty, or <code class="computeroutput">this-&gt;<a href="function.html#id2396343-bb">empty</a>()</code> if <code class="computeroutput">f</code> is empty.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
167
168    Will not throw when <code class="computeroutput">f</code> is a stateless function object.</p>
169</li>
170<li>
171<pre class="literallayout">function&amp; <a name="id2350723-bb"></a><span class="bold"><strong>operator</strong></span>=(<span class="bold"><strong>const</strong></span> <a href="../functionN.html" title="Class template functionN">functionN</a>&amp; f);</pre>
172<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Postconditions</span></b>:
173
174    <code class="computeroutput">*this</code> targets a copy of <code class="computeroutput">f</code>'s target, if it has one, or is empty if <code class="computeroutput">f.<a href="function.html#id2396343-bb">empty</a>()</code><br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
175
176    Will not throw when the target of <code class="computeroutput">f</code> is a stateless function object or a reference to the function object.</p>
177</li>
178<li>
179<pre class="literallayout">function&amp; <a name="id2406303-bb"></a><span class="bold"><strong>operator</strong></span>=(<span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&amp; f);</pre>
180<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Postconditions</span></b>:
181
182    <code class="computeroutput">*this</code> targets a copy of <code class="computeroutput">f</code>'s target, if it has one, or is empty if <code class="computeroutput">f.<a href="function.html#id2396343-bb">empty</a>()</code><br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
183
184    Will not throw when the target of <code class="computeroutput">f</code> is a stateless function object or a reference to the function object.</p>
185</li>
186<li>
187<pre class="literallayout"><a name="id2360840-bb"></a>~function();</pre>
188<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Effects</span></b>:
189
190    If <code class="computeroutput">!this-&gt;<a href="function.html#id2396343-bb">empty</a>()</code>, destroys the target of <code class="computeroutput">this</code>.</p>
191</li>
192</ol></div>
193</div>
194<div class="refsect2" lang="en">
195<a name="id2697164"></a><h3>
196<a name="id2342120-bb"></a><code class="computeroutput">function</code> modifiers</h3>
197<div class="orderedlist"><ol type="1">
198<li>
199<pre class="literallayout"><span class="type"><span class="bold"><strong>void</strong></span></span> <a name="id2342124-bb"></a>swap(<span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&amp; f);</pre>
200<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Effects</span></b>:
201
202    Interchanges the targets of <code class="computeroutput">*this</code> and <code class="computeroutput">f</code>.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
203
204    Will not throw.</p>
205</li>
206<li>
207<pre class="literallayout"><span class="type"><span class="bold"><strong>void</strong></span></span> <a name="id2434373-bb"></a>clear();</pre>
208<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Postconditions</span></b>:
209
210    <code class="computeroutput">this-&gt;<a href="function.html#id2396343-bb">empty</a>()</code><br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
211
212    Will not throw.</p>
213</li>
214</ol></div>
215</div>
216<div class="refsect2" lang="en">
217<a name="id2697294"></a><h3>
218<a name="id2396338-bb"></a><code class="computeroutput">function</code> capacity</h3>
219<div class="orderedlist"><ol type="1">
220<li>
221<pre class="literallayout"><span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id2396343-bb"></a>empty() <span class="bold"><strong>const</strong></span>;</pre>
222<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Returns</span></b>:
223
224    <code class="computeroutput">false</code> if <code class="computeroutput">this</code> has a target, and <code class="computeroutput">true</code> otherwise.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
225
226    Will not throw.</p>
227</li>
228<li>
229<pre class="literallayout"><a name="id2336149-bb"></a><span class="bold"><strong>operator</strong></span> safe_bool() <span class="bold"><strong>const</strong></span>;</pre>
230<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Returns</span></b>:
231
232    A <code class="computeroutput">safe_bool</code> that evaluates <code class="computeroutput">false</code> in a boolean context when <code class="computeroutput">this-&gt;<a href="function.html#id2396343-bb">empty</a>()</code>, and <code class="computeroutput">true</code> otherwise.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
233
234    Will not throw.</p>
235</li>
236<li>
237<pre class="literallayout"><span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id2371599-bb"></a><span class="bold"><strong>operator</strong></span>!() <span class="bold"><strong>const</strong></span>;</pre>
238<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Returns</span></b>:
239
240    <code class="computeroutput">this-&gt;<a href="function.html#id2396343-bb">empty</a>()</code><br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
241
242    Will not throw.</p>
243</li>
244</ol></div>
245</div>
246<div class="refsect2" lang="en">
247<a name="id2697505"></a><h3>
248<a name="id2378753-bb"></a><code class="computeroutput">function</code> target access</h3>
249<div class="orderedlist"><ol type="1">
250<li>
251<p><a name="id2378757-bb"></a></p>
252<pre class="literallayout"><span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Functor&gt; <span class="type">Functor*</span> <a name="id2378762-bb"></a>target();
253<span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Functor&gt; <span class="type"><span class="bold"><strong>const</strong></span> Functor*</span> <a name="id2376534-bb"></a>target() <span class="bold"><strong>const</strong></span>;</pre>
254<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Returns</span></b>:
255
256    If <code class="computeroutput">this</code> stores a target of type
257        <code class="computeroutput">Functor</code>, returns the address of the
258        target. Otherwise, returns the NULL
259        pointer.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
260
261    Will not throw.</p>
262</li>
263<li>
264<pre class="literallayout"><span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Functor&gt; <span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id2426358-bb"></a>contains(<span class="bold"><strong>const</strong></span> Functor&amp; f) <span class="bold"><strong>const</strong></span>;</pre>
265<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Returns</span></b>:
266
267    <code class="computeroutput">true</code> if <code class="computeroutput">this-&gt;<a href="function.html#id2378757-bb">target</a>&lt;Functor&gt;()</code> is non-NULL and <code class="computeroutput"><a href="../function_equal.html" title="Function template function_equal">function_equal</a>(*(this-&gt;target&lt;Functor&gt;()), f)</code></p>
268</li>
269</ol></div>
270</div>
271<div class="refsect2" lang="en">
272<a name="id2697705"></a><h3>
273<a name="id2404064-bb"></a><code class="computeroutput">function</code> invocation</h3>
274<div class="orderedlist"><ol type="1"><li>
275<pre class="literallayout"><span class="type">result_type</span> <a name="id2404069-bb"></a><span class="bold"><strong>operator</strong></span>()(arg1_type a1, arg2_type a2, ... , argN_type aN) <span class="bold"><strong>const</strong></span>;</pre>
276<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Effects</span></b>:
277
278    <code class="computeroutput">f(a1, a2, ..., aN)</code>, where <code class="computeroutput">f</code> is the target of <code class="computeroutput">*this</code>.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Returns</span></b>:
279
280    if <code class="computeroutput">R</code> is <code class="computeroutput">void</code>, nothing is returned; otherwise, the return value of the call to <code class="computeroutput">f</code> is returned.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
281
282    <code class="computeroutput"><a href="../bad_function_call.html" title="Class bad_function_call">bad_function_call</a></code> if <code class="computeroutput">this-&gt;<a href="function.html#id2396343-bb">empty</a>()</code>. Otherwise, may through any exception thrown by the target function <code class="computeroutput">f</code>.</p>
283</li></ol></div>
284</div>
285<div class="refsect2" lang="en">
286<a name="id2697840"></a><h3>
287<a name="id2408546-bb"></a><code class="computeroutput">function</code> specialized algorithms</h3>
288<div class="orderedlist"><ol type="1"><li>
289<pre class="literallayout"><span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator&gt; 
290  <span class="type"><span class="bold"><strong>void</strong></span></span> <a name="id2408551"></a>swap(<a href="function.html" title="Class template function">function</a>&lt;Signature, Allocator&gt;&amp; f1,
291            <a href="function.html" title="Class template function">function</a>&lt;Signature, Allocator&gt;&amp; f2);</pre>
292<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Effects</span></b>:
293
294    <code class="computeroutput">f1.<a href="function.html#id2342124-bb">swap</a>(f2)</code><br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Throws</span></b>:
295
296    Will not throw.</p>
297</li></ol></div>
298</div>
299<div class="refsect2" lang="en">
300<a name="id2697942"></a><h3>
301<a name="id2420066-bb"></a><code class="computeroutput">function</code> comparison operators</h3>
302<div class="orderedlist"><ol type="1">
303<li>
304<p><a name="id2341292"></a></p>
305<pre class="literallayout"><span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor&gt; 
306  <span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id2341297-bb"></a><span class="bold"><strong>operator</strong></span>==(<span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&lt;Signature, Allocator&gt;&amp; f, Functor g);
307<span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor&gt; 
308  <span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id2399796-bb"></a><span class="bold"><strong>operator</strong></span>==(Functor g, <span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&lt;Signature, Allocator&gt;&amp; f);
309<span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor&gt; 
310  <span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id2444136-bb"></a><span class="bold"><strong>operator</strong></span>==(<span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&lt;Signature, Allocator&gt;&amp; f,
311                  <a href="../reference_wrapper.html" title="Class template reference_wrapper">reference_wrapper</a>&lt;Functor&gt; g);
312<span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor&gt; 
313  <span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id2477463-bb"></a><span class="bold"><strong>operator</strong></span>==(<a href="../reference_wrapper.html" title="Class template reference_wrapper">reference_wrapper</a>&lt;Functor&gt; g,
314                  <span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&lt;Signature, Allocator&gt;&amp; f);
315<span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Signature1, <span class="bold"><strong>typename</strong></span> Allocator1, <span class="bold"><strong>typename</strong></span> Signature2,
316         <span class="bold"><strong>typename</strong></span> Allocator2&gt; 
317  <span class="type"><span class="bold"><strong>void</strong></span></span> <a name="id2378044-bb"></a><span class="bold"><strong>operator</strong></span>==(<span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&lt;Signature1, Allocator1&gt;&amp; f1,
318                  <span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&lt;Signature2, Allocator2&gt;&amp; f2);</pre>
319<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Returns</span></b>:
320
321    True when <code class="computeroutput">f</code> stores an object of
322        type <code class="computeroutput">Functor</code> and one of the following conditions applies:
323          <div class="itemizedlist"><ul type="disc">
324<li>
325<code class="computeroutput">g</code> is of type
326            <code class="computeroutput"><a href="../reference_wrapper.html" title="Class template reference_wrapper">reference_wrapper</a>&lt;Functor&gt;</code>
327            and <code class="computeroutput">f.target&lt;Functor&gt;() == g.<a href="../reference_wrapper.html#id2490294-bb">get_pointer</a>()</code>.</li>
328<li>
329<code class="computeroutput">g</code> is not of type
330            <code class="computeroutput"><a href="../reference_wrapper.html" title="Class template reference_wrapper">reference_wrapper</a>&lt;Functor&gt;</code>
331            and <code class="computeroutput">function_equals(*(f.target&lt;Functor&gt;()), g)</code>.</li>
332</ul></div><br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Notes</span></b>:
333
334    <code class="computeroutput"><a href="function.html" title="Class template function">function</a></code>
335        objects are not
336        <a href="../EqualityComparable.html" title="Concept EqualityComparable">EqualityComparable</a>.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Rationale</span></b>:
337
338    The <code class="computeroutput">safe_bool</code> conversion
339        opens a loophole whereby two <code class="computeroutput">function</code>
340        instances can be compared via <code class="computeroutput">==</code>, although this
341        is not feasible to implement. The undefined <code class="computeroutput">void
342        operator==</code> closes the loophole and ensures a
343        compile-time or link-time error.</p>
344</li>
345<li>
346<p><a name="id2352115"></a></p>
347<pre class="literallayout"><span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor&gt; 
348  <span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id2336228-bb"></a><span class="bold"><strong>operator</strong></span>!=(<span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&lt;Signature, Allocator&gt;&amp; f, Functor g);
349<span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor&gt; 
350  <span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id2337224-bb"></a><span class="bold"><strong>operator</strong></span>!=(Functor g, <span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&lt;Signature, Allocator&gt;&amp; f);
351<span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor&gt; 
352  <span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id2508816-bb"></a><span class="bold"><strong>operator</strong></span>!=(<span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&lt;Signature, Allocator&gt;&amp; f,
353                  <a href="../reference_wrapper.html" title="Class template reference_wrapper">reference_wrapper</a>&lt;Functor&gt; g);
354<span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor&gt; 
355  <span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id2407103-bb"></a><span class="bold"><strong>operator</strong></span>!=(<a href="../reference_wrapper.html" title="Class template reference_wrapper">reference_wrapper</a>&lt;Functor&gt; g,
356                  <span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&lt;Signature, Allocator&gt;&amp; f);
357<span class="bold"><strong>template</strong></span>&lt;<span class="bold"><strong>typename</strong></span> Signature1, <span class="bold"><strong>typename</strong></span> Allocator1, <span class="bold"><strong>typename</strong></span> Signature2,
358         <span class="bold"><strong>typename</strong></span> Allocator2&gt; 
359  <span class="type"><span class="bold"><strong>void</strong></span></span> <a name="id2469309-bb"></a><span class="bold"><strong>operator</strong></span>!=(<span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&lt;Signature1, Allocator1&gt;&amp; f1,
360                  <span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&lt;Signature2, Allocator2&gt;&amp; f2);</pre>
361<p><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Returns</span></b>:
362
363    True when <code class="computeroutput">f</code> does not store an
364        object of type <code class="computeroutput">Functor</code> or it stores an object of
365        type <code class="computeroutput">Functor</code> and one of the following conditions
366        applies:
367          <div class="itemizedlist"><ul type="disc">
368<li>
369<code class="computeroutput">g</code> is of type
370            <code class="computeroutput"><a href="../reference_wrapper.html" title="Class template reference_wrapper">reference_wrapper</a>&lt;Functor&gt;</code>
371            and <code class="computeroutput">f.target&lt;Functor&gt;() != g.<a href="../reference_wrapper.html#id2490294-bb">get_pointer</a>()</code>.</li>
372<li>
373<code class="computeroutput">g</code> is not of type
374            <code class="computeroutput"><a href="../reference_wrapper.html" title="Class template reference_wrapper">reference_wrapper</a>&lt;Functor&gt;</code>
375            and <code class="computeroutput">!function_equals(*(f.target&lt;Functor&gt;()), g)</code>.</li>
376</ul></div><br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Notes</span></b>:
377
378    <code class="computeroutput"><a href="function.html" title="Class template function">function</a></code>
379        objects are not
380        <a href="../EqualityComparable.html" title="Concept EqualityComparable">EqualityComparable</a>.<br><b xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision"><span class="term">Rationale</span></b>:
381
382    The <code class="computeroutput">safe_bool</code> conversion
383        opens a loophole whereby two <code class="computeroutput">function</code>
384        instances can be compared via <code class="computeroutput">!=</code>, although this
385        is not feasible to implement. The undefined <code class="computeroutput">void
386        operator!=</code> closes the loophole and ensures a
387        compile-time or link-time error.</p>
388</li>
389</ol></div>
390</div>
391</div>
392</div>
393<table width="100%"><tr>
394<td align="left"></td>
395<td align="right"><small>Copyright © 2001-2004 Douglas Gregor</small></td>
396</tr></table>
397<hr>
398<div class="spirit-nav">
399<a accesskey="p" href="../functionN.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../function/reference.html#header.boost.function.hpp"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="../function_equal.html"><img src="../images/next.png" alt="Next"></a>
400</div>
401</body>
402</html>
Note: See TracBrowser for help on using the repository browser.