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.68.1"> |
---|
7 | <link rel="start" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset"> |
---|
8 | <link rel="up" href="../function/reference.html#header.boost.function.hpp" title="Header <boost/function.hpp>"> |
---|
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 C++ Libraries" 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 — 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><<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<<span class="bold"><strong>void</strong></span>> > |
---|
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><R, T1, T2, ..., TN, Allocator> { |
---|
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 8. Boost.Lambda">Lambda</a> library support</em></span> |
---|
54 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Args> |
---|
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#id626791-bb">function</a>(); |
---|
62 | <a href="function.html#id684614-bb">function</a>(<span class="bold"><strong>const</strong></span> <a href="functionN.html" title="Class template functionN">functionN</a>&); |
---|
63 | <a href="function.html#id788052-bb">function</a>(<span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&); |
---|
64 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> F> <a href="function.html#id929357-bb">function</a>(F); |
---|
65 | function& <a href="function.html#id647080-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>&); |
---|
66 | function& <a href="function.html#id648333-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>&); |
---|
67 | <a href="function.html#id870861-bb">~function</a>(); |
---|
68 | |
---|
69 | <span class="emphasis"><em>// <a href="function.html#id972428-bb">modifiers</a></em></span> |
---|
70 | <span class="type"><span class="bold"><strong>void</strong></span></span> <a href="function.html#id972432-bb">swap</a>(<span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>&); |
---|
71 | <span class="type"><span class="bold"><strong>void</strong></span></span> <a href="function.html#id970240-bb">clear</a>(); |
---|
72 | |
---|
73 | <span class="emphasis"><em>// <a href="function.html#id835069-bb">capacity</a></em></span> |
---|
74 | <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="function.html#id835072-bb">empty</a>() <span class="bold"><strong>const</strong></span>; |
---|
75 | <a href="function.html#id967814-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#id753517-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#id697895-bb">target access</a></em></span> |
---|
79 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Functor> <span class="type">Functor*</span> <a href="function.html#id803790-bb">target</a>(); |
---|
80 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Functor> <span class="type"><span class="bold"><strong>const</strong></span> Functor*</span> <a href="function.html#id697875-bb">target</a>() <span class="bold"><strong>const</strong></span>; |
---|
81 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Functor> <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="function.html#id728918-bb">contains</a>(<span class="bold"><strong>const</strong></span> Functor&) <span class="bold"><strong>const</strong></span>; |
---|
82 | <span class="type"><span class="bold"><strong>const</strong></span> std::type_info&</span> <a href="function.html#id927594-bb">target_type</a>() <span class="bold"><strong>const</strong></span>; |
---|
83 | |
---|
84 | <span class="emphasis"><em>// <a href="function.html#id659523-bb">invocation</a></em></span> |
---|
85 | <span class="type">result_type</span> <a href="function.html#id659526-bb"><span class="bold"><strong>operator</strong></span>()</a>(arg1_type, arg2_type, ..., argN_type) <span class="bold"><strong>const</strong></span>; |
---|
86 | }; |
---|
87 | |
---|
88 | <span class="emphasis"><em>// <a href="function.html#id716667-bb">specialized algorithms</a></em></span> |
---|
89 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator> |
---|
90 | <span class="type"><span class="bold"><strong>void</strong></span></span> <a href="function.html#id754994-bb">swap</a>(<a href="function.html" title="Class template function">function</a><Signature, Allocator>&, <a href="function.html" title="Class template function">function</a><Signature, Allocator>&); |
---|
91 | |
---|
92 | <span class="emphasis"><em>// <a href="function.html#id758190-bb">comparison operators</a></em></span> |
---|
93 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor> |
---|
94 | <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="function.html#id717925-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><Signature, Allocator>&, Functor); |
---|
95 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor> |
---|
96 | <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="function.html#id786913-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><Signature, Allocator>&); |
---|
97 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor> |
---|
98 | <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="function.html#id683534-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><Signature, Allocator>&, |
---|
99 | <a href="reference_wrapper.html" title="Class template reference_wrapper">reference_wrapper</a><Functor>); |
---|
100 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor> |
---|
101 | <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="function.html#id733745-bb"><span class="bold"><strong>operator</strong></span>==</a>(<a href="reference_wrapper.html" title="Class template reference_wrapper">reference_wrapper</a><Functor>, |
---|
102 | <span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a><Signature, Allocator>&); |
---|
103 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Signature1, <span class="bold"><strong>typename</strong></span> Allocator1, <span class="bold"><strong>typename</strong></span> Signature2, |
---|
104 | <span class="bold"><strong>typename</strong></span> Allocator2> |
---|
105 | <span class="type"><span class="bold"><strong>void</strong></span></span> <a href="function.html#id768895-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><Signature1, Allocator1>&, |
---|
106 | <span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a><Signature2, Allocator2>&); |
---|
107 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor> |
---|
108 | <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="function.html#id792627-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><Signature, Allocator>&, Functor); |
---|
109 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor> |
---|
110 | <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="function.html#id897105-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><Signature, Allocator>&); |
---|
111 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor> |
---|
112 | <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="function.html#id827204-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><Signature, Allocator>&, |
---|
113 | <a href="reference_wrapper.html" title="Class template reference_wrapper">reference_wrapper</a><Functor>); |
---|
114 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor> |
---|
115 | <span class="type"><span class="bold"><strong>bool</strong></span></span> <a href="function.html#id730783-bb"><span class="bold"><strong>operator</strong></span>!=</a>(<a href="reference_wrapper.html" title="Class template reference_wrapper">reference_wrapper</a><Functor>, |
---|
116 | <span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a><Signature, Allocator>&); |
---|
117 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Signature1, <span class="bold"><strong>typename</strong></span> Allocator1, <span class="bold"><strong>typename</strong></span> Signature2, |
---|
118 | <span class="bold"><strong>typename</strong></span> Allocator2> |
---|
119 | <span class="type"><span class="bold"><strong>void</strong></span></span> <a href="function.html#id732711-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><Signature1, Allocator1>&, |
---|
120 | <span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a><Signature2, Allocator2>&);</pre></div> |
---|
121 | <div class="refsect1" lang="en"> |
---|
122 | <a name="id1212592"></a><h2>Description</h2> |
---|
123 | <p>Class template <a href="function.html" title="Class template function">function</a> is a thin |
---|
124 | 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 |
---|
125 | function type with N arguments and will will derive from |
---|
126 | <a href="functionN.html" title="Class template functionN">functionN</a> instantiated with the arguments |
---|
127 | it receives.</p> |
---|
128 | <p>The semantics of all operations in class template |
---|
129 | <a href="function.html" title="Class template function">function</a> are equivalent to that of the |
---|
130 | underlying <a href="functionN.html" title="Class template functionN">functionN</a> object, although |
---|
131 | additional member functions are required to allow proper copy |
---|
132 | construction and copy assignment of function objects.</p> |
---|
133 | <div class="refsect2" lang="en"> |
---|
134 | <a name="id1212651"></a><h3> |
---|
135 | <a name="boost.functionconstruct-copy-destruct"></a><code class="computeroutput">function</code> construct/copy/destruct</h3> |
---|
136 | <div class="orderedlist"><ol type="1"> |
---|
137 | <li> |
---|
138 | <pre class="literallayout"><a name="id626791-bb"></a>function();</pre> |
---|
139 | <div class="variablelist"><table border="0"> |
---|
140 | <col align="left" valign="top"> |
---|
141 | <tbody> |
---|
142 | <tr> |
---|
143 | <td> |
---|
144 | <span class="term">Postconditions:</span></td> |
---|
145 | <td><code class="computeroutput">this-><a href="function.html#id835072-bb">empty</a>()</code></td> |
---|
146 | </tr> |
---|
147 | <tr> |
---|
148 | <td> |
---|
149 | <span class="term">Throws:</span></td> |
---|
150 | <td>Will not throw.</td> |
---|
151 | </tr> |
---|
152 | </tbody> |
---|
153 | </table></div> |
---|
154 | </li> |
---|
155 | <li> |
---|
156 | <pre class="literallayout"><a name="id684614-bb"></a>function(<span class="bold"><strong>const</strong></span> <a href="functionN.html" title="Class template functionN">functionN</a>& f);</pre> |
---|
157 | <div class="variablelist"><table border="0"> |
---|
158 | <col align="left" valign="top"> |
---|
159 | <tbody> |
---|
160 | <tr> |
---|
161 | <td> |
---|
162 | <span class="term">Postconditions:</span></td> |
---|
163 | <td>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#id835072-bb">empty</a>()</code>.</td> |
---|
164 | </tr> |
---|
165 | <tr> |
---|
166 | <td> |
---|
167 | <span class="term">Throws:</span></td> |
---|
168 | <td>Will not throw unless copying the target of <code class="computeroutput">f</code> throws.</td> |
---|
169 | </tr> |
---|
170 | </tbody> |
---|
171 | </table></div> |
---|
172 | </li> |
---|
173 | <li> |
---|
174 | <pre class="literallayout"><a name="id788052-bb"></a>function(<span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>& f);</pre> |
---|
175 | <div class="variablelist"><table border="0"> |
---|
176 | <col align="left" valign="top"> |
---|
177 | <tbody> |
---|
178 | <tr> |
---|
179 | <td> |
---|
180 | <span class="term">Postconditions:</span></td> |
---|
181 | <td>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#id835072-bb">empty</a>()</code>.</td> |
---|
182 | </tr> |
---|
183 | <tr> |
---|
184 | <td> |
---|
185 | <span class="term">Throws:</span></td> |
---|
186 | <td>Will not throw unless copying the target of <code class="computeroutput">f</code> throws.</td> |
---|
187 | </tr> |
---|
188 | </tbody> |
---|
189 | </table></div> |
---|
190 | </li> |
---|
191 | <li> |
---|
192 | <pre class="literallayout"><span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> F> <a name="id929357-bb"></a>function(F f);</pre> |
---|
193 | <div class="variablelist"><table border="0"> |
---|
194 | <col align="left" valign="top"> |
---|
195 | <tbody> |
---|
196 | <tr> |
---|
197 | <td> |
---|
198 | <span class="term">Requires:</span></td> |
---|
199 | <td>F is a function object Callable from <code class="computeroutput">this</code>.</td> |
---|
200 | </tr> |
---|
201 | <tr> |
---|
202 | <td> |
---|
203 | <span class="term">Postconditions:</span></td> |
---|
204 | <td> |
---|
205 | <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-><a href="function.html#id835072-bb">empty</a>()</code> if <code class="computeroutput">f</code> is empty.</td> |
---|
206 | </tr> |
---|
207 | </tbody> |
---|
208 | </table></div> |
---|
209 | </li> |
---|
210 | <li> |
---|
211 | <pre class="literallayout">function& <a name="id647080-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>& f);</pre> |
---|
212 | <div class="variablelist"><table border="0"> |
---|
213 | <col align="left" valign="top"> |
---|
214 | <tbody><tr> |
---|
215 | <td> |
---|
216 | <span class="term">Postconditions:</span></td> |
---|
217 | <td>If copy construction does not throw, <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#id835072-bb">empty</a>()</code>. If copy construction does throw, <code class="computeroutput">this-><a href="function.html#id835072-bb">empty</a>()</code>.</td> |
---|
218 | </tr></tbody> |
---|
219 | </table></div> |
---|
220 | </li> |
---|
221 | <li> |
---|
222 | <pre class="literallayout">function& <a name="id648333-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>& f);</pre> |
---|
223 | <div class="variablelist"><table border="0"> |
---|
224 | <col align="left" valign="top"> |
---|
225 | <tbody> |
---|
226 | <tr> |
---|
227 | <td> |
---|
228 | <span class="term">Postconditions:</span></td> |
---|
229 | <td>If copy construction of the target of <code class="computeroutput">f</code> does not throw, <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#id835072-bb">empty</a>()</code>. </td> |
---|
230 | </tr> |
---|
231 | <tr> |
---|
232 | <td> |
---|
233 | <span class="term">Throws:</span></td> |
---|
234 | <td>Will not throw when the target of <code class="computeroutput">f</code> is a stateless function object or a reference to the function object. If copy construction does throw, <code class="computeroutput">this-><a href="function.html#id835072-bb">empty</a>()</code>.</td> |
---|
235 | </tr> |
---|
236 | </tbody> |
---|
237 | </table></div> |
---|
238 | </li> |
---|
239 | <li> |
---|
240 | <pre class="literallayout"><a name="id870861-bb"></a>~function();</pre> |
---|
241 | <div class="variablelist"><table border="0"> |
---|
242 | <col align="left" valign="top"> |
---|
243 | <tbody><tr> |
---|
244 | <td> |
---|
245 | <span class="term">Effects:</span></td> |
---|
246 | <td>If <code class="computeroutput">!this-><a href="function.html#id835072-bb">empty</a>()</code>, destroys the target of <code class="computeroutput">this</code>.</td> |
---|
247 | </tr></tbody> |
---|
248 | </table></div> |
---|
249 | </li> |
---|
250 | </ol></div> |
---|
251 | </div> |
---|
252 | <div class="refsect2" lang="en"> |
---|
253 | <a name="id1213160"></a><h3> |
---|
254 | <a name="id972428-bb"></a><code class="computeroutput">function</code> modifiers</h3> |
---|
255 | <div class="orderedlist"><ol type="1"> |
---|
256 | <li> |
---|
257 | <pre class="literallayout"><span class="type"><span class="bold"><strong>void</strong></span></span> <a name="id972432-bb"></a>swap(<span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a>& f);</pre> |
---|
258 | <div class="variablelist"><table border="0"> |
---|
259 | <col align="left" valign="top"> |
---|
260 | <tbody><tr> |
---|
261 | <td> |
---|
262 | <span class="term">Effects:</span></td> |
---|
263 | <td>Interchanges the targets of <code class="computeroutput">*this</code> and <code class="computeroutput">f</code>.</td> |
---|
264 | </tr></tbody> |
---|
265 | </table></div> |
---|
266 | </li> |
---|
267 | <li> |
---|
268 | <pre class="literallayout"><span class="type"><span class="bold"><strong>void</strong></span></span> <a name="id970240-bb"></a>clear();</pre> |
---|
269 | <div class="variablelist"><table border="0"> |
---|
270 | <col align="left" valign="top"> |
---|
271 | <tbody> |
---|
272 | <tr> |
---|
273 | <td> |
---|
274 | <span class="term">Postconditions:</span></td> |
---|
275 | <td><code class="computeroutput">this-><a href="function.html#id835072-bb">empty</a>()</code></td> |
---|
276 | </tr> |
---|
277 | <tr> |
---|
278 | <td> |
---|
279 | <span class="term">Throws:</span></td> |
---|
280 | <td>Will not throw.</td> |
---|
281 | </tr> |
---|
282 | </tbody> |
---|
283 | </table></div> |
---|
284 | </li> |
---|
285 | </ol></div> |
---|
286 | </div> |
---|
287 | <div class="refsect2" lang="en"> |
---|
288 | <a name="id1213282"></a><h3> |
---|
289 | <a name="id835069-bb"></a><code class="computeroutput">function</code> capacity</h3> |
---|
290 | <div class="orderedlist"><ol type="1"> |
---|
291 | <li> |
---|
292 | <pre class="literallayout"><span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id835072-bb"></a>empty() <span class="bold"><strong>const</strong></span>;</pre> |
---|
293 | <div class="variablelist"><table border="0"> |
---|
294 | <col align="left" valign="top"> |
---|
295 | <tbody> |
---|
296 | <tr> |
---|
297 | <td> |
---|
298 | <span class="term">Returns:</span></td> |
---|
299 | <td> |
---|
300 | <code class="computeroutput">false</code> if <code class="computeroutput">this</code> has a target, and <code class="computeroutput">true</code> otherwise.</td> |
---|
301 | </tr> |
---|
302 | <tr> |
---|
303 | <td> |
---|
304 | <span class="term">Throws:</span></td> |
---|
305 | <td>Will not throw.</td> |
---|
306 | </tr> |
---|
307 | </tbody> |
---|
308 | </table></div> |
---|
309 | </li> |
---|
310 | <li> |
---|
311 | <pre class="literallayout"><a name="id967814-bb"></a><span class="bold"><strong>operator</strong></span> safe_bool() <span class="bold"><strong>const</strong></span>;</pre> |
---|
312 | <div class="variablelist"><table border="0"> |
---|
313 | <col align="left" valign="top"> |
---|
314 | <tbody> |
---|
315 | <tr> |
---|
316 | <td> |
---|
317 | <span class="term">Returns:</span></td> |
---|
318 | <td>A <code class="computeroutput">safe_bool</code> that evaluates <code class="computeroutput">false</code> in a boolean context when <code class="computeroutput">this-><a href="function.html#id835072-bb">empty</a>()</code>, and <code class="computeroutput">true</code> otherwise.</td> |
---|
319 | </tr> |
---|
320 | <tr> |
---|
321 | <td> |
---|
322 | <span class="term">Throws:</span></td> |
---|
323 | <td>Will not throw.</td> |
---|
324 | </tr> |
---|
325 | </tbody> |
---|
326 | </table></div> |
---|
327 | </li> |
---|
328 | <li> |
---|
329 | <pre class="literallayout"><span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id753517-bb"></a><span class="bold"><strong>operator</strong></span>!() <span class="bold"><strong>const</strong></span>;</pre> |
---|
330 | <div class="variablelist"><table border="0"> |
---|
331 | <col align="left" valign="top"> |
---|
332 | <tbody> |
---|
333 | <tr> |
---|
334 | <td> |
---|
335 | <span class="term">Returns:</span></td> |
---|
336 | <td><code class="computeroutput">this-><a href="function.html#id835072-bb">empty</a>()</code></td> |
---|
337 | </tr> |
---|
338 | <tr> |
---|
339 | <td> |
---|
340 | <span class="term">Throws:</span></td> |
---|
341 | <td>Will not throw.</td> |
---|
342 | </tr> |
---|
343 | </tbody> |
---|
344 | </table></div> |
---|
345 | </li> |
---|
346 | </ol></div> |
---|
347 | </div> |
---|
348 | <div class="refsect2" lang="en"> |
---|
349 | <a name="id1213492"></a><h3> |
---|
350 | <a name="id697895-bb"></a><code class="computeroutput">function</code> target access</h3> |
---|
351 | <div class="orderedlist"><ol type="1"> |
---|
352 | <li> |
---|
353 | <p><a name="id697899-bb"></a></p> |
---|
354 | <pre class="literallayout"><span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Functor> <span class="type">Functor*</span> <a name="id803790-bb"></a>target(); |
---|
355 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Functor> <span class="type"><span class="bold"><strong>const</strong></span> Functor*</span> <a name="id697875-bb"></a>target() <span class="bold"><strong>const</strong></span>;</pre> |
---|
356 | <div class="variablelist"><table border="0"> |
---|
357 | <col align="left" valign="top"> |
---|
358 | <tbody> |
---|
359 | <tr> |
---|
360 | <td> |
---|
361 | <span class="term">Returns:</span></td> |
---|
362 | <td>If <code class="computeroutput">this</code> stores a target of type |
---|
363 | <code class="computeroutput">Functor</code>, returns the address of the |
---|
364 | target. Otherwise, returns the NULL |
---|
365 | pointer.</td> |
---|
366 | </tr> |
---|
367 | <tr> |
---|
368 | <td> |
---|
369 | <span class="term">Throws:</span></td> |
---|
370 | <td>Will not throw.</td> |
---|
371 | </tr> |
---|
372 | </tbody> |
---|
373 | </table></div> |
---|
374 | </li> |
---|
375 | <li> |
---|
376 | <pre class="literallayout"><span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Functor> <span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id728918-bb"></a>contains(<span class="bold"><strong>const</strong></span> Functor& f) <span class="bold"><strong>const</strong></span>;</pre> |
---|
377 | <div class="variablelist"><table border="0"> |
---|
378 | <col align="left" valign="top"> |
---|
379 | <tbody><tr> |
---|
380 | <td> |
---|
381 | <span class="term">Returns:</span></td> |
---|
382 | <td> |
---|
383 | <code class="computeroutput">true</code> if <code class="computeroutput">this-><a href="function.html#id697899-bb">target</a><Functor>()</code> is non-NULL and <code class="computeroutput"><a href="function_equal.html" title="Function template function_equal">function_equal</a>(*(this->target<Functor>()), f)</code> |
---|
384 | </td> |
---|
385 | </tr></tbody> |
---|
386 | </table></div> |
---|
387 | </li> |
---|
388 | <li> |
---|
389 | <pre class="literallayout"><span class="type"><span class="bold"><strong>const</strong></span> std::type_info&</span> <a name="id927594-bb"></a>target_type() <span class="bold"><strong>const</strong></span>;</pre> |
---|
390 | <div class="variablelist"><table border="0"> |
---|
391 | <col align="left" valign="top"> |
---|
392 | <tbody> |
---|
393 | <tr> |
---|
394 | <td> |
---|
395 | <span class="term">Returns:</span></td> |
---|
396 | <td> |
---|
397 | <code class="computeroutput">typeid</code> of the target function object, or <code class="computeroutput">typeid(void)</code> if <code class="computeroutput">this-><a href="function.html#id835072-bb">empty</a>()</code>.</td> |
---|
398 | </tr> |
---|
399 | <tr> |
---|
400 | <td> |
---|
401 | <span class="term">Throws:</span></td> |
---|
402 | <td>Will not throw.</td> |
---|
403 | </tr> |
---|
404 | </tbody> |
---|
405 | </table></div> |
---|
406 | </li> |
---|
407 | </ol></div> |
---|
408 | </div> |
---|
409 | <div class="refsect2" lang="en"> |
---|
410 | <a name="id1213759"></a><h3> |
---|
411 | <a name="id659523-bb"></a><code class="computeroutput">function</code> invocation</h3> |
---|
412 | <div class="orderedlist"><ol type="1"><li> |
---|
413 | <pre class="literallayout"><span class="type">result_type</span> <a name="id659526-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> |
---|
414 | <div class="variablelist"><table border="0"> |
---|
415 | <col align="left" valign="top"> |
---|
416 | <tbody> |
---|
417 | <tr> |
---|
418 | <td> |
---|
419 | <span class="term">Effects:</span></td> |
---|
420 | <td> |
---|
421 | <code class="computeroutput">f(a1, a2, ..., aN)</code>, where <code class="computeroutput">f</code> is the target of <code class="computeroutput">*this</code>.</td> |
---|
422 | </tr> |
---|
423 | <tr> |
---|
424 | <td> |
---|
425 | <span class="term">Returns:</span></td> |
---|
426 | <td>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.</td> |
---|
427 | </tr> |
---|
428 | <tr> |
---|
429 | <td> |
---|
430 | <span class="term">Throws:</span></td> |
---|
431 | <td> |
---|
432 | <code class="computeroutput"><a href="bad_function_call.html" title="Class bad_function_call">bad_function_call</a></code> if <code class="computeroutput">this-><a href="function.html#id835072-bb">empty</a>()</code>. Otherwise, may through any exception thrown by the target function <code class="computeroutput">f</code>.</td> |
---|
433 | </tr> |
---|
434 | </tbody> |
---|
435 | </table></div> |
---|
436 | </li></ol></div> |
---|
437 | </div> |
---|
438 | <div class="refsect2" lang="en"> |
---|
439 | <a name="id1213893"></a><h3> |
---|
440 | <a name="id716667-bb"></a><code class="computeroutput">function</code> specialized algorithms</h3> |
---|
441 | <div class="orderedlist"><ol type="1"><li> |
---|
442 | <pre class="literallayout"><span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator> |
---|
443 | <span class="type"><span class="bold"><strong>void</strong></span></span> <a name="id754994-bb"></a>swap(<a href="function.html" title="Class template function">function</a><Signature, Allocator>& f1, |
---|
444 | <a href="function.html" title="Class template function">function</a><Signature, Allocator>& f2);</pre> |
---|
445 | <div class="variablelist"><table border="0"> |
---|
446 | <col align="left" valign="top"> |
---|
447 | <tbody><tr> |
---|
448 | <td> |
---|
449 | <span class="term">Effects:</span></td> |
---|
450 | <td><code class="computeroutput">f1.<a href="function.html#id972432-bb">swap</a>(f2)</code></td> |
---|
451 | </tr></tbody> |
---|
452 | </table></div> |
---|
453 | </li></ol></div> |
---|
454 | </div> |
---|
455 | <div class="refsect2" lang="en"> |
---|
456 | <a name="id1213988"></a><h3> |
---|
457 | <a name="id758190-bb"></a><code class="computeroutput">function</code> comparison operators</h3> |
---|
458 | <div class="orderedlist"><ol type="1"> |
---|
459 | <li> |
---|
460 | <p><a name="id717922-bb"></a></p> |
---|
461 | <pre class="literallayout"><span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor> |
---|
462 | <span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id717925-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><Signature, Allocator>& f, Functor g); |
---|
463 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor> |
---|
464 | <span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id786913-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><Signature, Allocator>& f); |
---|
465 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor> |
---|
466 | <span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id683534-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><Signature, Allocator>& f, |
---|
467 | <a href="reference_wrapper.html" title="Class template reference_wrapper">reference_wrapper</a><Functor> g); |
---|
468 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor> |
---|
469 | <span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id733745-bb"></a><span class="bold"><strong>operator</strong></span>==(<a href="reference_wrapper.html" title="Class template reference_wrapper">reference_wrapper</a><Functor> g, |
---|
470 | <span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a><Signature, Allocator>& f); |
---|
471 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Signature1, <span class="bold"><strong>typename</strong></span> Allocator1, <span class="bold"><strong>typename</strong></span> Signature2, |
---|
472 | <span class="bold"><strong>typename</strong></span> Allocator2> |
---|
473 | <span class="type"><span class="bold"><strong>void</strong></span></span> <a name="id768895-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><Signature1, Allocator1>& f1, |
---|
474 | <span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a><Signature2, Allocator2>& f2);</pre> |
---|
475 | <div class="variablelist"><table border="0"> |
---|
476 | <col align="left" valign="top"> |
---|
477 | <tbody> |
---|
478 | <tr> |
---|
479 | <td> |
---|
480 | <span class="term">Returns:</span></td> |
---|
481 | <td>True when <code class="computeroutput">f</code> stores an object of |
---|
482 | type <code class="computeroutput">Functor</code> and one of the following conditions applies: |
---|
483 | <div class="itemizedlist"><ul type="disc"> |
---|
484 | <li> |
---|
485 | <code class="computeroutput">g</code> is of type |
---|
486 | <code class="computeroutput"><a href="reference_wrapper.html" title="Class template reference_wrapper">reference_wrapper</a><Functor></code> |
---|
487 | and <code class="computeroutput">f.target<Functor>() == g.<a href="reference_wrapper.html#id623846-bb">get_pointer</a>()</code>.</li> |
---|
488 | <li> |
---|
489 | <code class="computeroutput">g</code> is not of type |
---|
490 | <code class="computeroutput"><a href="reference_wrapper.html" title="Class template reference_wrapper">reference_wrapper</a><Functor></code> |
---|
491 | and <code class="computeroutput">function_equals(*(f.target<Functor>()), g)</code>.</li> |
---|
492 | </ul></div> |
---|
493 | </td> |
---|
494 | </tr> |
---|
495 | <tr> |
---|
496 | <td> |
---|
497 | <span class="term">Notes:</span></td> |
---|
498 | <td> |
---|
499 | <code class="computeroutput"><a href="function.html" title="Class template function">function</a></code> |
---|
500 | objects are not |
---|
501 | <a href="../EqualityComparable.html" title="Concept EqualityComparable">EqualityComparable</a>.</td> |
---|
502 | </tr> |
---|
503 | <tr> |
---|
504 | <td> |
---|
505 | <span class="term">Rationale:</span></td> |
---|
506 | <td>The <code class="computeroutput">safe_bool</code> conversion |
---|
507 | opens a loophole whereby two <code class="computeroutput">function</code> |
---|
508 | instances can be compared via <code class="computeroutput">==</code>, although this |
---|
509 | is not feasible to implement. The undefined <code class="computeroutput">void |
---|
510 | operator==</code> closes the loophole and ensures a |
---|
511 | compile-time or link-time error.</td> |
---|
512 | </tr> |
---|
513 | </tbody> |
---|
514 | </table></div> |
---|
515 | </li> |
---|
516 | <li> |
---|
517 | <p><a name="id792623-bb"></a></p> |
---|
518 | <pre class="literallayout"><span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor> |
---|
519 | <span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id792627-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><Signature, Allocator>& f, Functor g); |
---|
520 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor> |
---|
521 | <span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id897105-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><Signature, Allocator>& f); |
---|
522 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor> |
---|
523 | <span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id827204-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><Signature, Allocator>& f, |
---|
524 | <a href="reference_wrapper.html" title="Class template reference_wrapper">reference_wrapper</a><Functor> g); |
---|
525 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Signature, <span class="bold"><strong>typename</strong></span> Allocator, <span class="bold"><strong>typename</strong></span> Functor> |
---|
526 | <span class="type"><span class="bold"><strong>bool</strong></span></span> <a name="id730783-bb"></a><span class="bold"><strong>operator</strong></span>!=(<a href="reference_wrapper.html" title="Class template reference_wrapper">reference_wrapper</a><Functor> g, |
---|
527 | <span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a><Signature, Allocator>& f); |
---|
528 | <span class="bold"><strong>template</strong></span><<span class="bold"><strong>typename</strong></span> Signature1, <span class="bold"><strong>typename</strong></span> Allocator1, <span class="bold"><strong>typename</strong></span> Signature2, |
---|
529 | <span class="bold"><strong>typename</strong></span> Allocator2> |
---|
530 | <span class="type"><span class="bold"><strong>void</strong></span></span> <a name="id732711-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><Signature1, Allocator1>& f1, |
---|
531 | <span class="bold"><strong>const</strong></span> <a href="function.html" title="Class template function">function</a><Signature2, Allocator2>& f2);</pre> |
---|
532 | <div class="variablelist"><table border="0"> |
---|
533 | <col align="left" valign="top"> |
---|
534 | <tbody> |
---|
535 | <tr> |
---|
536 | <td> |
---|
537 | <span class="term">Returns:</span></td> |
---|
538 | <td>True when <code class="computeroutput">f</code> does not store an |
---|
539 | object of type <code class="computeroutput">Functor</code> or it stores an object of |
---|
540 | type <code class="computeroutput">Functor</code> and one of the following conditions |
---|
541 | applies: |
---|
542 | <div class="itemizedlist"><ul type="disc"> |
---|
543 | <li> |
---|
544 | <code class="computeroutput">g</code> is of type |
---|
545 | <code class="computeroutput"><a href="reference_wrapper.html" title="Class template reference_wrapper">reference_wrapper</a><Functor></code> |
---|
546 | and <code class="computeroutput">f.target<Functor>() != g.<a href="reference_wrapper.html#id623846-bb">get_pointer</a>()</code>.</li> |
---|
547 | <li> |
---|
548 | <code class="computeroutput">g</code> is not of type |
---|
549 | <code class="computeroutput"><a href="reference_wrapper.html" title="Class template reference_wrapper">reference_wrapper</a><Functor></code> |
---|
550 | and <code class="computeroutput">!function_equals(*(f.target<Functor>()), g)</code>.</li> |
---|
551 | </ul></div> |
---|
552 | </td> |
---|
553 | </tr> |
---|
554 | <tr> |
---|
555 | <td> |
---|
556 | <span class="term">Notes:</span></td> |
---|
557 | <td> |
---|
558 | <code class="computeroutput"><a href="function.html" title="Class template function">function</a></code> |
---|
559 | objects are not |
---|
560 | <a href="../EqualityComparable.html" title="Concept EqualityComparable">EqualityComparable</a>.</td> |
---|
561 | </tr> |
---|
562 | <tr> |
---|
563 | <td> |
---|
564 | <span class="term">Rationale:</span></td> |
---|
565 | <td>The <code class="computeroutput">safe_bool</code> conversion |
---|
566 | opens a loophole whereby two <code class="computeroutput">function</code> |
---|
567 | instances can be compared via <code class="computeroutput">!=</code>, although this |
---|
568 | is not feasible to implement. The undefined <code class="computeroutput">void |
---|
569 | operator!=</code> closes the loophole and ensures a |
---|
570 | compile-time or link-time error.</td> |
---|
571 | </tr> |
---|
572 | </tbody> |
---|
573 | </table></div> |
---|
574 | </li> |
---|
575 | </ol></div> |
---|
576 | </div> |
---|
577 | </div> |
---|
578 | </div> |
---|
579 | <table width="100%"><tr> |
---|
580 | <td align="left"></td> |
---|
581 | <td align="right"><small>Copyright © 2001-2004 Douglas Gregor</small></td> |
---|
582 | </tr></table> |
---|
583 | <hr> |
---|
584 | <div class="spirit-nav"> |
---|
585 | <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> |
---|
586 | </div> |
---|
587 | </body> |
---|
588 | </html> |
---|