Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/bind/bind.html @ 12

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

added boost

File size: 42.9 KB
RevLine 
[12]1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3        <head>
4                <title>Boost: bind.hpp documentation</title>
5                <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
6        </head>
7        <body style="MARGIN-LEFT: 5%; MARGIN-RIGHT: 5%" bgColor="white">
8                <table width="100%" border="0">
9                        <tr>
10                                <td width="277"><IMG height="86" alt="boost.png (6897 bytes)" src="../../boost.png" width="277">
11                                </td>
12                                <td align="center">
13                                        <h1>bind.hpp</h1>
14                                </td>
15                        </tr>
16                        <tr>
17                                <td colSpan="2" height="64">&nbsp;</td>
18                        </tr>
19                </table>
20                <h2>Contents</h2>
21                <h3 style="MARGIN-LEFT: 20pt"><A href="#Purpose">Purpose</A></h3>
22                <h4 style="MARGIN-LEFT: 40pt"><A href="#with_functions">Using bind with functions and
23                                function pointers</A></h4>
24                <h4 style="MARGIN-LEFT: 40pt"><A href="#with_function_objects">Using bind with function
25                                objects</A></h4>
26                <h4 style="MARGIN-LEFT: 40pt"><A href="#with_member_pointers">Using bind with pointers
27                                to members</A></h4>
28                <h4 style="MARGIN-LEFT: 40pt"><A href="#nested_binds">Using nested binds for function
29                                composition</A></h4>
30                <h4 style="MARGIN-LEFT: 40pt"><A href="#operators">Overloaded operators</A></h4>
31                <h3 style="MARGIN-LEFT: 20pt"><A href="#Examples">Examples</A></h3>
32                <h4 style="MARGIN-LEFT: 40pt"><A href="#with_algorithms">Using bind with standard
33                                algorithms</A></h4>
34                <h4 style="MARGIN-LEFT: 40pt"><A href="#with_boost_function">Using bind with
35                                Boost.Function</A></h4>
36                <h3 style="MARGIN-LEFT: 20pt"><A href="#Limitations">Limitations</A></h3>
37                <h3 style="MARGIN-LEFT: 20pt"><A href="#FAQ">Frequently Asked Questions</A></h3>
38                <h4 style="MARGIN-LEFT: 40pt"><A href="#Q_doesnt_compile">Why doesn't this compile?</A></h4>
39                <h4 style="MARGIN-LEFT: 40pt"><A href="#Q_does_compile">Why does this compile? It
40                                should not.</A></h4>
41                <h4 style="MARGIN-LEFT: 40pt"><A href="#Q_forms">What is the difference between bind(f,
42                                ...) and bind&lt;R&gt;(f, ...)?</A></h4>
43                <h4 style="MARGIN-LEFT: 40pt"><A href="#Q_win32_api">Does <b>bind</b> work with Windows
44                                API functions?</A></h4>
45                <h4 style="MARGIN-LEFT: 40pt"><A href="#Q_com">Does <b>bind</b> work with COM methods?</A></h4>
46                <h4 style="MARGIN-LEFT: 40pt"><A href="#Q_mac">Does <b>bind</b> work with Mac toolbox
47                                functions?</A></h4>
48                <h4 style="MARGIN-LEFT: 40pt"><A href="#Q_extern_C">Does <b>bind</b> work with extern
49                                "C" functions?</A></h4>
50                <h4 style="MARGIN-LEFT: 40pt"><A href="#Q_auto_stdcall">Why doesn't <b>bind</b> automatically
51                                recognize nonstandard functions?</A></h4>
52                <h3 style="MARGIN-LEFT: 20pt"><A href="#Troubleshooting">Troubleshooting</A></h3>
53                <h4 style="MARGIN-LEFT: 40pt"><A href="#err_num_args">Incorrect number of arguments</A></h4>
54                <h4 style="MARGIN-LEFT: 40pt"><A href="#err_signature">The function object cannot be
55                                called with the specified arguments</A></h4>
56                <h4 style="MARGIN-LEFT: 40pt"><A href="#err_arg_access">Accessing an argument that does
57                                not exist</A></h4>
58                <h4 style="MARGIN-LEFT: 40pt"><A href="#err_short_form">Inappropriate use of bind(f,
59                                ...)</A></h4>
60                <h4 style="MARGIN-LEFT: 40pt"><A href="#err_long_form">Inappropriate use of
61                                bind&lt;R&gt;(f, ...)</A></h4>
62                <h4 style="MARGIN-LEFT: 40pt"><A href="#err_nonstd">Binding a nonstandard function</A></h4>
63                <h4 style="MARGIN-LEFT: 40pt"><A href="#err_const_arg"><b>const</b> in signatures</A></h4>
64                <h4 style="MARGIN-LEFT: 40pt"><A href="#err_msvc_using">MSVC specific: using
65                                boost::bind;</A></h4>
66                <h4 style="MARGIN-LEFT: 40pt"><A href="#err_msvc_class_template">MSVC specific: class
67                                templates shadow function templates</A></h4>
68                <h4 style="MARGIN-LEFT: 40pt"><A href="#err_msvc_ellipsis">MSVC specific: ... in
69                                signatures treated as type</A></h4>
70                <h3 style="MARGIN-LEFT: 20pt"><A href="#Interface">Interface</A></h3>
71                <h4 style="MARGIN-LEFT: 40pt"><A href="#Synopsis">Synopsis</A></h4>
72                <h4 style="MARGIN-LEFT: 40pt"><A href="#CommonRequirements">Common requirements</A></h4>
73                <h4 style="MARGIN-LEFT: 40pt"><A href="#CommonDefinitions">Common definitions</A></h4>
74                <h4 style="MARGIN-LEFT: 40pt"><A href="#bind">bind</A></h4>
75                <h4 style="MARGIN-LEFT: 40pt"><A href="#AdditionalOverloads">Additional overloads</A></h4>
76                <h3 style="MARGIN-LEFT: 20pt"><A href="#Implementation">Implementation</A></h3>
77                <h4 style="MARGIN-LEFT: 40pt"><A href="#Files">Files</A></h4>
78                <h4 style="MARGIN-LEFT: 40pt"><A href="#Dependencies">Dependencies</A></h4>
79                <h4 style="MARGIN-LEFT: 40pt"><A href="#NumberOfArguments">Number of Arguments</A></h4>
80                <h4 style="MARGIN-LEFT: 40pt"><A href="#stdcall">"__stdcall", "__cdecl", "__fastcall",
81                                and "pascal" Support</A></h4>
82                <h4 style="MARGIN-LEFT: 40pt"><A href="#visit_each"><b>visit_each</b> support</A></h4>
83                <h3 style="MARGIN-LEFT: 20pt"><A href="#Acknowledgements">Acknowledgements</A></h3>
84                <h2><a name="Purpose">Purpose</a></h2>
85                <p><b>boost::bind</b> is a generalization of the standard functions <b>std::bind1st</b>
86                        and <b>std::bind2nd</b>. It supports arbitrary function objects, functions,
87                        function pointers, and member function pointers, and is able to bind any
88                        argument to a specific value or route input arguments into arbitrary positions. <b>bind</b>
89                        does not place any requirements on the function object; in particular, it does
90                        not need the <b>result_type</b>, <b>first_argument_type</b> and <b>second_argument_type</b>
91                        standard typedefs.
92                </p>
93                <h3><a name="with_functions">Using bind with functions and function pointers</a></h3>
94                <p>Given these definitions:
95                </p>
96                <pre>int f(int a, int b)
97{
98    return a + b;
99}
100
101int g(int a, int b, int c)
102{
103    return a + b + c;
104}
105</pre>
106                <p><tt>bind(f, 1, 2)</tt> will produce a "nullary" function object that takes no
107                        arguments and returns <tt>f(1, 2)</tt>. Similarly, <tt>bind(g, 1, 2, 3)()</tt> is
108                        equivalent to <tt>g(1, 2, 3)</tt>.
109                </p>
110                <p>It is possible to selectively bind only some of the arguments. <tt>bind(f, _1, 5)(x)</tt>
111                        is equivalent to <tt>f(x, 5)</tt>; here <b>_1</b>
112                is a placeholder argument that means "substitute with the first input
113                argument."
114                <p>For comparison, here is the same operation expressed with the standard library
115                        primitives:
116                </p>
117                <pre>std::bind2nd(std::ptr_fun(f), 5)(x);
118</pre>
119                <p><b>bind</b> covers the functionality of <b>std::bind1st</b> as well:
120                </p>
121                <pre>std::bind1st(std::ptr_fun(f), 5)(x);   // f(5, x)
122bind(f, 5, _1)(x);                     // f(5, x)
123</pre>
124                <p><b>bind</b> can handle functions with more than two arguments, and its argument
125                        substitution mechanism is more general:
126                </p>
127                <pre>bind(f, _2, _1)(x, y);                 // f(y, x)
128
129bind(g, _1, 9, _1)(x);                 // g(x, 9, x)
130
131bind(g, _3, _3, _3)(x, y, z);          // g(z, z, z)
132
133bind(g, _1, _1, _1)(x, y, z);          // g(x, x, x)
134</pre>
135                <p>Note that, in the last example, the function object produced by <tt>bind(g, _1, _1,
136                                _1)</tt> does not contain references to any arguments beyond the first, but
137                        it can still be used with more than one argument. Any extra arguments are
138                        silently ignored, just like the first and the second argument are ignored in
139                        the third example.
140                </p>
141                <p>The arguments that <b>bind</b> takes are copied and held internally by the
142                        returned function object. For example, in the following code:
143                </p>
144                <pre>int i = 5;
145
146bind(f, i, _1);
147</pre>
148                <p>a copy of the value of <b>i</b> is stored into the function object. <A href="ref.html">
149                                boost::ref</A> and <A href="ref.html">boost::cref</A> can be used to make
150                        the function object store a reference to an object, rather than a copy:
151                </p>
152                <pre>int i = 5;
153
154bind(f, ref(i), _1);
155
156bind(f, cref(42), _1);
157</pre>
158                <h3><a name="with_function_objects">Using bind with function objects</a></h3>
159                <p><b>bind</b> is not limited to functions; it accepts arbitrary function objects.
160                        In the general case, the return type of the generated function object's <b>operator()</b>
161                        has to be specified explicitly (without a <b>typeof</b> operator the return
162                        type cannot be inferred):
163                </p>
164                <pre>struct F
165{
166    int operator()(int a, int b) { return a - b; }
167    bool operator()(long a, long b) { return a == b; }
168};
169
170F f;
171
172int x = 104;
173
174bind&lt;int&gt;(f, _1, _1)(x);          // f(x, x), i.e. zero
175</pre>
176                <p>Some compilers have trouble with the <tt>bind&lt;R&gt;(f, ...)</tt> syntax. For
177                        portability reasons, an alternative way to express the above is supported:</p>
178                <pre>boost::bind(boost::type&lt;int&gt;(), f, _1, _1)(x);
179</pre>
180                <P>Note, however, that the alternative syntax is provided only as a workaround. It
181                        is not part of the interface.</P>
182                <P>When the function object exposes a nested type named <b>result_type</b>, the
183                        explicit return type can be omitted:
184                </P>
185                <pre>int x = 8;
186
187bind(std::less&lt;int&gt;(), _1, 9)(x); // x &lt; 9
188</pre>
189                <p>[Note: the ability to omit the return type is not available on all compilers.]
190                </p>
191                <h3><a name="with_member_pointers">Using bind with pointers to members</a></h3>
192                <p>Pointers to member functions and pointers to data members are not function
193                        objects, because they do not support <tt>operator()</tt>. For convenience, <b>bind</b>
194                        accepts member pointers as its first argument, and the behavior is as if <A href="mem_fn.html">
195                                boost::mem_fn</A> has been used to convert the member pointer into a
196                        function object. In other words, the expression
197                </p>
198                <pre>bind(&amp;X::f, <i>args</i>)
199</pre>
200                <p>is equivalent to
201                </p>
202                <pre>bind&lt;R&gt;(<A href="mem_fn.html" >mem_fn</A>(&amp;X::f), <i>args</i>)
203</pre>
204                <p>where <b>R</b> is the return type of <b>X::f</b> (for member functions) or the
205                        type of the member (for data members.)
206                </p>
207                <p>[Note: <b>mem_fn</b> creates function objects that are able to accept a pointer,
208                        a reference, or a smart pointer to an object as its first argument; for
209                        additional information, see the <b>mem_fn</b> <A href="mem_fn.html">documentation</A>.]
210                </p>
211                <p>Example:
212                </p>
213                <pre>struct X
214{
215    bool f(int a);
216};
217
218X x;
219
220shared_ptr&lt;X&gt; p(new X);
221
222int i = 5;
223
224bind(&amp;X::f, ref(x), _1)(i);         // x.f(i)
225bind(&amp;X::f, &amp;x, _1)(i);                 //(&amp;x)-&gt;f(i)
226bind(&amp;X::f, x, _1)(i);                      // (<i>internal copy of x</i>).f(i)
227bind(&amp;X::f, p, _1)(i);                      // (<i>internal copy of p</i>)-&gt;f(i)
228</pre>
229                <p>The last two examples are interesting in that they produce "self-contained"
230                        function objects. <tt>bind(&amp;X::f, x, _1)</tt> stores a copy of <b>x</b>. <tt>bind(&amp;X::f,
231                                p, _1)</tt> stores a copy of <b>p</b>, and since <b>p</b> is a <A href="../smart_ptr/shared_ptr.htm">
232                                boost::shared_ptr</A>, the function object retains a reference to its
233                        instance of <b>X</b> and will remain valid even when <b>p</b> goes out of scope
234                        or is <b>reset()</b>.
235                </p>
236                <h3><a name="nested_binds">Using nested binds for function composition</a></h3>
237                <p>Some of the arguments passed to <b>bind</b> may be nested <b>bind</b> expressions
238                        themselves:
239                </p>
240                <pre>bind(f, bind(g, _1))(x);               // f(g(x))
241</pre>
242                <p>The inner <STRONG>bind</STRONG> expressions are evaluated, in unspecified order,
243                        before the outer <STRONG>bind</STRONG> when the function object is called; the
244                        results of the evaluation are then substituted in their place when the outer <STRONG>
245                                bind</STRONG> is evaluated. In the example above, when the function object
246                        is called with the argument list <tt>(x)</tt>, <tt>bind(g, _1)(x)</tt> is
247                        evaluated first, yielding <tt>g(x)</tt>, and then <tt>bind(f, g(x))(x)</tt> is
248                        evaluated, yielding the final result <tt>f(g(x))</tt>.
249                </p>
250                <P>This feature of <b>bind</b> can be used to perform function composition. See <A href="bind_as_compose.cpp">
251                                bind_as_compose.cpp</A> for an example that demonstrates how to use <b>bind</b>
252                        to achieve similar functionality to <A href="../compose/index.htm">Boost.Compose</A>.
253                </P>
254                <p>Note that the first argument - the bound function object - is not evaluated,
255                        even when it's a function object that is produced by <STRONG>bind</STRONG> or a
256                        placeholder argument, so the example below does not work as expected:
257                </p>
258                <pre>typedef void (*pf)(int);
259
260std::vector&lt;pf&gt; v;
261
262std::for_each(v.begin(), v.end(), bind(_1, 5));
263</pre>
264                <p>The desired effect can be achieved via a helper function object <STRONG>apply</STRONG>
265                        that applies its first argument, as a function object, to the rest of its
266                        argument list. For convenience, an implementation of <STRONG>apply</STRONG> is
267                        provided in the <STRONG>boost/bind/apply.hpp</STRONG> header file. Here is how
268                        the modified version of the previous example looks like:
269                </p>
270                <pre>typedef void (*pf)(int);
271
272std::vector&lt;pf&gt; v;
273
274std::for_each(v.begin(), v.end(), bind(apply&lt;void&gt;(), _1, 5));
275</pre>
276                <P>Although the first argument is, by default, not evaluated, all other arguments
277                        are. Sometimes it is necessary not to evaluate arguments subsequent to the
278                        first, even when they are nested <STRONG>bind</STRONG> subexpressions. This can
279                        be achieved with the help of another function object, <STRONG>protect</STRONG>,
280                        that masks the type so that <STRONG>bind</STRONG> does not recognize and
281                        evaluate it. When called, <STRONG>protect</STRONG> simply forwards the argument
282                        list to the other function object unmodified.</P>
283                <P>The header <STRONG>boost/bind/protect.hpp</STRONG> contains an implementation of <STRONG>
284                                protect</STRONG>. To protect a <STRONG>bind</STRONG> function object from
285                        evaluation, use <tt>protect(bind(f, ...))</tt>.</P>
286                <h3><a name="operators">Overloaded operators</a> (new in Boost 1.33)</h3>
287                <p>For convenience, the function objects produced by <tt>bind</tt> overload
288                        the logical not operator <STRONG>!</STRONG> and the relational operators <STRONG>==</STRONG>,
289                        <STRONG>!=</STRONG>, <STRONG>&lt;</STRONG>, <STRONG>&lt;=</STRONG>, <STRONG>&gt;</STRONG>,
290                        <STRONG>&gt;=</STRONG>.</p>
291                <P><tt>!bind(f, ...)</tt> is equivalent to <tt>bind( <EM>logical_not</EM>(), bind(f,
292                                ...) )</tt>, where <tt><EM>logical_not</EM></tt> is a function object that
293                        takes one argument <tt>x</tt> and returns <tt>!x</tt>.</P>
294                <P><tt>bind(f, ...) <EM>op</EM> x</tt>, where <EM>op</EM> is a relational operator,
295                        is equivalent to <tt>bind( <EM>relation</EM>(), bind(f, ...), x )</tt>, where <em>relation</em>
296                        is a function object that takes two arguments <tt>a</tt> and <tt>b</tt> and
297                        returns <tt>a <EM>op</EM> b</tt>.</P>
298                <P>What this means in practice is that you can conveniently negate the result of
299                        <tt>bind</tt>:</P>
300                <P><tt>std::remove_if( first, last, !bind( &amp;X::visible, _1 ) ); // remove invisible
301                                objects</tt></P>
302                <P>and compare the result of <tt>bind</tt> against a value:</P>
303                <P><tt>std::find_if( first, last, bind( &amp;X::name, _1 ) == "peter" );</tt></P>
304                <P>against a placeholder:</P>
305                <P><tt>bind( &amp;X::name, _1 ) == _2</tt></P>
306                <P>or against another <tt>bind</tt> expression:</P>
307                <P><tt>std::sort( first, last, bind( &amp;X::name, _1 ) &lt; bind( &amp;X::name, _2 )
308                                ); // sort by name</tt></P>
309                <h2><a name="Examples">Examples</a></h2>
310                <h3><a name="with_algorithms">Using bind with standard algorithms</a></h3>
311                <pre>class image;
312
313class animation
314{
315public:
316
317    void advance(int ms);
318    bool inactive() const;
319    void render(image &amp; target) const;
320};
321
322std::vector&lt;animation&gt; anims;
323
324template&lt;class C, class P&gt; void erase_if(C &amp; c, P pred)
325{
326    c.erase(std::remove_if(c.begin(), c.end(), pred), c.end());
327}
328
329void update(int ms)
330{
331    std::for_each(anims.begin(), anims.end(), boost::bind(&amp;animation::advance, _1, ms));
332    erase_if(anims, boost::mem_fn(&amp;animation::inactive));
333}
334
335void render(image &amp; target)
336{
337    std::for_each(anims.begin(), anims.end(), boost::bind(&amp;animation::render, _1, boost::ref(target)));
338}
339</pre>
340                <h3><a name="with_boost_function">Using bind with Boost.Function</a></h3>
341                <pre>class button
342{
343public:
344
345    <A href="../function/index.html" >boost::function</A>&lt;void&gt; onClick;
346};
347
348class player
349{
350public:
351
352    void play();
353    void stop();
354};
355
356button playButton, stopButton;
357player thePlayer;
358
359void connect()
360{
361    playButton.onClick = boost::bind(&amp;player::play, &amp;thePlayer);
362    stopButton.onClick = boost::bind(&amp;player::stop, &amp;thePlayer);
363}
364</pre>
365                <h2><a name="Limitations">Limitations</a></h2>
366                <p>The function objects generated by <b>bind</b> take their arguments by reference
367                        and cannot, therefore, accept non-const temporaries or literal constants. This
368                        is an inherent limitation of the C++ language, known as <A href="http://std.dkuug.dk/jtc1/sc22/wg21/docs/papers/2002/n1385.htm">
369                                the forwarding problem</A>.</p>
370                <p>The library uses signatures of the form
371                </p>
372                <pre>template&lt;class T&gt; void f(T &amp; t);
373</pre>
374                <p>to accept arguments of arbitrary types and pass them on unmodified. As noted,
375                        this does not work with non-const r-values.
376                </p>
377                <p>An oft-proposed "solution" to this problem is to add an overload:
378                </p>
379                <pre>template&lt;class T&gt; void f(T &amp; t);
380template&lt;class T&gt; void f(T const &amp; t);
381</pre>
382                <p>Unfortunately, this (a) requires providing 512 overloads for nine arguments and
383                        (b) does not actually work for const arguments, both l- and r-values, since the
384                        two templates produce the exact same signature and cannot be partially ordered.
385                </p>
386                <p>[Note: this is a dark corner of the language, and the <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#214">
387                                corresponding issue</a> has only recently been resolved.]
388                </p>
389                <h2><a name="FAQ">Frequently Asked Questions</a></h2>
390                <h3><a name="Q_doesnt_compile">Why doesn't this compile?</a></h3>
391                <p>See the <A href="#Troubleshooting">dedicated Troubleshooting section</A>.</p>
392                <h3><a name="Q_does_compile">Why does this compile? It should not.</a></h3>
393                <p>Probably because you used the general <tt>bind&lt;R&gt;(f, ...)</tt> syntax,
394                        thereby instructing <b>bind</b> to not "inspect" <b>f</b> to detect arity and
395                        return type errors.</p>
396                <h3><a name="Q_forms">What is the difference between bind(f, ...) and bind&lt;R&gt;(f,
397                                ...)?</a></h3>
398                <p>The first form instructs <b>bind</b> to inspect the type of <b>f</b> in order to
399                        determine its arity (number of arguments) and return type. Arity errors will be
400                        detected at "bind time". This syntax, of course, places some requirements on <b>f</b>.
401                        It must be a function, function pointer, member function pointer, or a function
402                        object that defines a nested type named <b>result_type</b>; in short, it must
403                        be something that <b>bind</b> can recognize.</p>
404                <p>The second form instructs <b>bind</b> to <b>not</b> attempt to recognize the
405                        type of <b>f</b>. It is generally used with function objects that do not, or
406                        cannot, expose <b>result_type</b>, but it can also be used with nonstandard
407                        functions. For example, the current implementation does not automatically
408                        recognize variable-argument functions like <b>printf</b>, so you will have to
409                        use <tt>bind&lt;int&gt;(printf, ...)</tt>. Note that an alternative <tt>bind(type&lt;R&gt;(),
410                                f, ...)</tt> syntax is supported for portability reasons.</p>
411                <p>Another important factor to consider is that compilers without partial template
412                        specialization or function template partial ordering support cannot handle the
413                        first form when <b>f</b> is a function object, and in most cases will not
414                        handle the second form when <b>f</b> is a function (pointer) or a member
415                        function pointer.</p>
416                <h3><a name="Q_win32_api">Does <b>bind</b> work with Windows API functions?</a></h3>
417                <p>Yes, if you <A href="#stdcall">#define BOOST_BIND_ENABLE_STDCALL</A>. An
418                        alternative is to treat the function as a <A href="#with_function_objects">generic
419                                function object</A> and use the <tt>bind&lt;R&gt;(f, ...)</tt> syntax.</p>
420                <h3><a name="Q_com">Does <b>bind</b> work with COM methods?</a></h3>
421                <p>Yes, if you <A href="#stdcall">#define BOOST_MEM_FN_ENABLE_STDCALL</A>.</p>
422                <h3><a name="Q_mac">Does <b>bind</b> work with Mac toolbox functions?</a></h3>
423                <p>Yes, if you <A href="#stdcall">#define BOOST_BIND_ENABLE_PASCAL</A>. An
424                        alternative is to treat the function as a <A href="#with_function_objects">generic
425                                function object</A> and use the <tt>bind&lt;R&gt;(f, ...)</tt> syntax.</p>
426                <h3><a name="Q_extern_C">Does <b>bind</b> work with extern "C" functions?</a></h3>
427                <p>Sometimes. On some platforms, pointers to extern "C" functions are equivalent to
428                        "ordinary" function pointers, so they work fine. Other platforms treat them as
429                        different types. A platform-specific implementation of <b>bind</b> is expected
430                        to handle the problem transparently; this implementation does not. As usual,
431                        the workaround is to treat the function as a <A href="#with_function_objects">generic
432                                function object</A> and use the <tt>bind&lt;R&gt;(f, ...)</tt> syntax.</p>
433                <h3><a name="Q_auto_stdcall">Why doesn't <b>bind</b> automatically recognize
434                                nonstandard functions?</a></h3>
435                <p>Non-portable extensions, in general, should default to off to prevent vendor
436                        lock-in. Had the <A href="#stdcall">appropriate macros</A> been defined
437                        automatically, you could have accidentally taken advantage of them without
438                        realizing that your code is, perhaps, no longer portable. In addition, some
439                        compilers have the option to make <b>__stdcall</b> (<STRONG>__fastcall</STRONG>)
440                        their default calling convention, in which case no separate support would be
441                        necessary.</p>
442                <h2><a name="Troubleshooting">Troubleshooting</a></h2>
443                <h3><a name="err_num_args">Incorrect number of arguments</a></h3>
444                <p>In a <tt>bind(f, a1, a2, ..., aN)</tt> expression, the function object <b>f</b> must
445                        be able to take exactly <b>N</b> arguments. This error is normally detected at
446                        "bind time"; in other words, the compilation error is reported on the line
447                        where bind() is invoked:</p>
448                <pre>int f(int, int);
449
450int main()
451{
452    boost::bind(f, 1);    // error, f takes two arguments
453    boost::bind(f, 1, 2); // OK
454}
455</pre>
456                <p>A common variation of this error is to forget that member functions have an
457                        implicit "this" argument:</p>
458                <pre>struct X
459{
460    int f(int);
461}
462
463int main()
464{
465    boost::bind(&amp;X::f, 1);     // error, X::f takes two arguments
466    boost::bind(&amp;X::f, <b>_1</b>, 1); // OK
467}
468</pre>
469                <h3><a name="err_signature">The function object cannot be called with the specified
470                                arguments</a></h3>
471                <p>As in normal function calls, the function object that is bound must be
472                        compatible with the argument list. The incompatibility will usually be detected
473                        by the compiler at "call time" and the result is typically an error in <b>bind.hpp</b>
474                        on a line that looks like:</p>
475                <pre>    return f(a[a1_], a[a2_]);
476</pre>
477                <p>An example of this kind of error:</p>
478                <pre>int f(int);
479
480int main()
481{
482    boost::bind(f, "incompatible");      // OK so far, no call
483    boost::bind(f, "incompatible")();    // error, "incompatible" is not an int
484    boost::bind(f, _1);                  // OK
485    boost::bind(f, _1)("incompatible");  // error, "incompatible" is not an int
486}
487</pre>
488                <h3><a name="err_arg_access">Accessing an argument that does not exist</a></h3>
489                <p>The placeholder <b>_N</b> selects the argument at position <b>N</b> from the
490                        argument list passed at "call time." Naturally, it is an error to attempt to
491                        access beyond the end of this list:</p>
492                <pre>int f(int);
493
494int main()
495{
496    boost::bind(f, _1);                  // OK
497    boost::bind(f, _1)();                // error, there is no argument number 1
498}
499</pre>
500                <p>The error is usually reported in <b>bind.hpp</b>, at a line similar to:</p>
501                <pre>    return f(a[a1_]);
502</pre>
503                <p>When emulating <tt>std::bind1st(f, a)</tt>, a common mistake of this category is
504                        to type <tt>bind(f, a, _2)</tt> instead of the correct <tt>bind(f, a, _1)</tt>.</p>
505                <h3><a name="err_short_form">Inappropriate use of bind(f, ...)</a></h3>
506                <p>The <tt>bind(f, a1, a2, ..., aN)</tt> <A href="#Q_forms">form</A> causes
507                        automatic recognition of the type of <b>f</b>. It will not work with arbitrary
508                        function objects; <b>f</b> must be a function or a member function pointer.</p>
509                <p>It is possible to use this form with function objects that define <b>result_type</b>,
510                        but <b>only on compilers</b> that support partial specialization and partial
511                        ordering. In particular, MSVC up to version 7.0 does not support this syntax
512                        for function objects.</p>
513                <h3><a name="err_long_form">Inappropriate use of bind&lt;R&gt;(f, ...)</a></h3>
514                <p>The <tt>bind&lt;R&gt;(f, a1, a2, ..., aN)</tt> <A href="#Q_forms">form</A> supports
515                        arbitrary function objects.</p>
516                <p>It is possible (but not recommended) to use this form with functions or member
517                        function pointers, but <b>only on compilers</b> that support partial ordering.
518                        In particular, MSVC up to version 7.0 does not fully support this syntax for
519                        functions and member function pointers.</p>
520                <h3><a name="err_nonstd">Binding a nonstandard function</a></h3>
521                <p>By default, the <tt>bind(f, a1, a2, ..., aN)</tt> <A href="#Q_forms">form</A> recognizes
522                        "ordinary" C++ functions and function pointers. <A href="#stdcall">Functions that
523                                use a different calling convention</A>, or variable-argument functions such
524                        as <STRONG>std::printf</STRONG>, do not work. The general <tt>bind&lt;R&gt;(f, a1,
525                                a2, ..., aN)</tt> <A href="#Q_forms">form</A> works with nonstandard
526                        functions.
527                </p>
528                <p>On some platforms, extern "C" functions, like <b>std::strcmp</b>, are not
529                        recognized by the short form of bind.
530                </p>
531                <P>See also <A href="#stdcall">"__stdcall" and "pascal" Support</A>.</P>
532                <h3><a name="err_const_arg"><b>const</b> in signatures</a></h3>
533                <p>Some compilers, including MSVC 6.0 and Borland C++ 5.5.1, have problems with the
534                        top-level <b>const</b> in function signatures:
535                </p>
536                <pre>int f(int const);
537
538int main()
539{
540    boost::bind(f, 1);     // error
541}
542</pre>
543                <p>Workaround: remove the <b>const</b> qualifier from the argument.
544                </p>
545                <h3><a name="err_msvc_using">MSVC specific: using boost::bind;</a></h3>
546                <p>On MSVC (up to version 7.0), when <b>boost::bind</b> is brought into scope with
547                        an using declaration:
548                </p>
549                <pre>using boost::bind;
550</pre>
551                <p>the syntax <tt>bind&lt;R&gt;(f, ...)</tt> does not work. Workaround: either use
552                        the qualified name, <b>boost::bind</b>, or use an using directive instead:
553                </p>
554                <pre>using namespace boost;
555</pre>
556                <h3><a name="err_msvc_class_template">MSVC specific: class templates shadow function
557                                templates</a></h3>
558                <p>On MSVC (up to version 7.0), a nested class template named <b>bind</b> will
559                        shadow the function template <b>boost::bind</b>, breaking the <tt>bind&lt;R&gt;(f,
560                                ...)</tt> syntax. Unfortunately, some libraries contain nested class
561                        templates named <b>bind</b> (ironically, such code is often an MSVC specific
562                        workaround.)</p>
563                <P>The workaround is to use the alternative <tt>bind(type&lt;R&gt;(), f, ...)</tt> syntax.</P>
564                <h3><a name="err_msvc_ellipsis">MSVC specific: ... in signatures treated as type</a></h3>
565                <p>MSVC (up to version 7.0) treats the ellipsis in a variable argument function
566                        (such as <b>std::printf</b>) as a type. Therefore, it will accept the
567                        (incorrect in the current implementation) form:
568                </p>
569                <pre>    bind(printf, "%s\n", _1);
570</pre>
571                <p>and will reject the correct version:
572                </p>
573                <pre>    bind&lt;int&gt;(printf, "%s\n", _1);
574</pre>
575                <h2><a name="Interface">Interface</a></h2>
576                <h3><a name="Synopsis">Synopsis</a></h3>
577                <pre>namespace boost
578{
579
580// no arguments
581
582template&lt;class R, class F&gt; <i>unspecified-1</i> <A href="#bind_1" >bind</A>(F f);
583
584template&lt;class F&gt; <i>unspecified-1-1</i> <A href="#bind_1_1" >bind</A>(F f);
585
586template&lt;class R&gt; <i>unspecified-2</i> <A href="#bind_2" >bind</A>(R (*f) ());
587
588// one argument
589
590template&lt;class R, class F, class A1&gt; <i>unspecified-3</i> <A href="#bind_3" >bind</A>(F f, A1 a1);
591
592template&lt;class F, class A1&gt; <i>unspecified-3-1</i> <A href="#bind_3_1" >bind</A>(F f, A1 a1);
593
594template&lt;class R, class B1, class A1&gt; <i>unspecified-4</i> <A href="#bind_4" >bind</A>(R (*f) (B1), A1 a1);
595
596template&lt;class R, class T, class A1&gt; <i>unspecified-5</i> <A href="#bind_5" >bind</A>(R (T::*f) (), A1 a1);
597
598template&lt;class R, class T, class A1&gt; <i>unspecified-6</i> <A href="#bind_6" >bind</A>(R (T::*f) () const, A1 a1);
599
600template&lt;class R, class T, class A1&gt; <i>unspecified-6-1</i> <A href="#bind_6_1" >bind</A>(R T::*f, A1 a1);
601
602// two arguments
603
604template&lt;class R, class F, class A1, class A2&gt; <i>unspecified-7</i> <A href="#bind_7" >bind</A>(F f, A1 a1, A2 a2);
605
606template&lt;class F, class A1, class A2&gt; <i>unspecified-7-1</i> <A href="#bind_7_1" >bind</A>(F f, A1 a1, A2 a2);
607
608template&lt;class R, class B1, class B2, class A1, class A2&gt; <i>unspecified-8</i> <A href="#bind_8" >bind</A>(R (*f) (B1, B2), A1 a1, A2 a2);
609
610template&lt;class R, class T, class B1, class A1, class A2&gt; <i>unspecified-9</i> <A href="#bind_9" >bind</A>(R (T::*f) (B1), A1 a1, A2 a2);
611
612template&lt;class R, class T, class B1, class A1, class A2&gt; <i>unspecified-10</i> <A href="#bind_10" >bind</A>(R (T::*f) (B1) const, A1 a1, A2 a2);
613
614// implementation defined number of additional overloads for more arguments
615
616}
617
618namespace
619{
620
621<i>unspecified-placeholder-type-1</i> _1;
622
623<i>unspecified-placeholder-type-2</i> _2;
624
625<i>unspecified-placeholder-type-3</i> _3;
626
627// implementation defined number of additional placeholder definitions
628
629}
630</pre>
631                <h3><a name="CommonRequirements">Common requirements</a></h3>
632                <p>All <tt><i>unspecified-N</i></tt> types returned by <b>bind</b> are <b>CopyConstructible</b>.
633                        <tt><i>unspecified-N</i>::result_type</tt> is defined as the return type of <tt><i>unspecified-N</i>::operator()</tt>.</p>
634                <p>All <tt><i>unspecified-placeholder-N</i></tt> types are <b>CopyConstructible</b>.
635                        Their copy constructors do not throw exceptions.</p>
636                <h3><a name="CommonDefinitions">Common definitions</a></h3>
637                <p>The function µ(x, v<sub>1</sub>, v<sub>2</sub>, ..., v<sub>m</sub>), where m is
638                        a nonnegative integer, is defined as:</p>
639                <ul>
640                        <li>
641                                <tt>x.get()</tt>, when <tt>x</tt> is of type <tt><A href="ref.html">boost::reference_wrapper</A>&lt;T&gt;</tt>
642                                for some type <tt>T</tt>;
643                        <li>
644                                v<sub>k</sub>, when <tt>x</tt>
645                        is (a copy of) the placeholder _k for some positive integer k;
646                        <li>
647                                <tt>x(v<sub>1</sub>, v<sub>2</sub>, ..., v<sub>m</sub>)</tt> when <tt>x</tt> is
648                                (a copy of) a function object returned by <b>bind</b>;
649                        <li>
650                                <tt>x</tt> otherwise.</li></ul>
651                <h3><a name="bind">bind</a></h3>
652                <h4><a name="bind_1">template&lt;class R, class F&gt; <i>unspecified-1</i> bind(F f)</a></h4>
653                <blockquote>
654                        <p><b>Returns:</b> A function object <i>&#955;</i> such that the expression <tt>&#955;(v<sub>1</sub>,
655                                        v<sub>2</sub>, ..., v<sub>m</sub>)</tt> is equivalent to <tt><b>f</b>()</tt>,
656                                implicitly converted to <b>R</b>.</p>
657                        <p><b>Throws:</b> Nothing unless the copy constructor of <b>F</b> throws an
658                                exception.</p>
659                </blockquote>
660                <h4><a name="bind_1_1">template&lt;class F&gt; <i>unspecified-1-1</i> bind(F f)</a></h4>
661                <blockquote>
662                        <p><b>Effects:</b> Equivalent to <tt>bind&lt;typename F::result_type, F&gt;(f);</tt></p>
663                        <p><b>Notes:</b> Implementations are allowed to infer the return type of <b>f</b> via
664                                other means as an extension, without relying on the <tt>result_type</tt> member.</p>
665                </blockquote>
666                <h4><a name="bind_2">template&lt;class R&gt; <i>unspecified-2</i> bind(R (*f) ())</a></h4>
667                <blockquote>
668                        <p><b>Returns:</b> A function object <i>&#955;</i> such that the expression <tt>&#955;(v<sub>1</sub>,
669                                        v<sub>2</sub>, ..., v<sub>m</sub>)</tt> is equivalent to <tt><b>f</b>()</tt>.</p>
670                        <p><b>Throws:</b> Nothing.</p>
671                </blockquote>
672                <h4><a name="bind_3">template&lt;class R, class F, class A1&gt; <i>unspecified-3</i> bind(F
673                                f, A1 a1)</a></h4>
674                <blockquote>
675                        <p><b>Returns:</b> A function object <i>&#955;</i> such that the expression <tt>&#955;(v<sub>1</sub>,
676                                        v<sub>2</sub>, ..., v<sub>m</sub>)</tt> is equivalent to <tt><b>f</b>(µ(<b>a1</b>,
677                                        v<sub>1</sub>, v<sub>2</sub>, ..., v<sub>m</sub>))</tt>, implicitly
678                                converted to <b>R</b>.</p>
679                        <p><b>Throws:</b> Nothing unless the copy constructors of <b>F</b> or <b>A1</b> throw
680                                an exception.</p>
681                </blockquote>
682                <h4><a name="bind_3_1">template&lt;class F, class A1&gt; <i>unspecified-3-1</i> bind(F
683                                f, A1 a1)</a></h4>
684                <blockquote>
685                        <p><b>Effects:</b> Equivalent to <tt>bind&lt;typename F::result_type, F, A1&gt;(f, a1);</tt></p>
686                        <p><b>Notes:</b> Implementations are allowed to infer the return type of <b>f</b> via
687                                other means as an extension, without relying on the <tt>result_type</tt> member.</p>
688                </blockquote>
689                <h4><a name="bind_4">template&lt;class R, class B1, class A1&gt; <i>unspecified-4</i> bind(R
690                                (*f) (B1), A1 a1)</a></h4>
691                <blockquote>
692                        <p><b>Returns:</b> A function object <i>&#955;</i> such that the expression <tt>&#955;(v<sub>1</sub>,
693                                        v<sub>2</sub>, ..., v<sub>m</sub>)</tt> is equivalent to <tt><b>f</b>(µ(<b>a1</b>,
694                                        v<sub>1</sub>, v<sub>2</sub>, ..., v<sub>m</sub>))</tt>.</p>
695                        <p><b>Throws:</b> Nothing unless the copy constructor of <b>A1</b> throws an
696                                exception.</p>
697                </blockquote>
698                <h4><a name="bind_5">template&lt;class R, class T, class A1&gt; <i>unspecified-5</i> bind(R
699                                (T::*f) (), A1 a1)</a></h4>
700                <blockquote>
701                        <p><b>Effects:</b> Equivalent to <tt>bind&lt;R&gt;(<A href="mem_fn.html">boost::mem_fn</A>(f),
702                                        a1);</tt></p>
703                </blockquote>
704                <h4><a name="bind_6">template&lt;class R, class T, class A1&gt; <i>unspecified-6</i> bind(R
705                                (T::*f) () const, A1 a1)</a></h4>
706                <blockquote>
707                        <p><b>Effects:</b> Equivalent to <tt>bind&lt;R&gt;(<A href="mem_fn.html">boost::mem_fn</A>(f),
708                                        a1);</tt></p>
709                </blockquote>
710                <h4><a name="bind_6_1">template&lt;class R, class T, class A1&gt; <i>unspecified-6-1</i>
711                                bind(R T::*f, A1 a1)</a></h4>
712                <blockquote>
713                        <p><b>Effects:</b> Equivalent to <tt>bind&lt;R&gt;(<A href="mem_fn.html">boost::mem_fn</A>(f),
714                                        a1);</tt></p>
715                </blockquote>
716                <h4><a name="bind_7">template&lt;class R, class F, class A1, class A2&gt; <i>unspecified-7</i>
717                                bind(F f, A1 a1, A2 a2)</a></h4>
718                <blockquote>
719                        <p><b>Returns:</b> A function object <i>&#955;</i> such that the expression <tt>&#955;(v<sub>1</sub>,
720                                        v<sub>2</sub>, ..., v<sub>m</sub>)</tt> is equivalent to <tt><b>f</b>(µ(<b>a1</b>,
721                                        v<sub>1</sub>, v<sub>2</sub>, ..., v<sub>m</sub>), µ(<b>a2</b>, v<sub>1</sub>,
722                                        v<sub>2</sub>, ..., v<sub>m</sub>))</tt>, implicitly converted to <b>R</b>.</p>
723                        <p><b>Throws:</b> Nothing unless the copy constructors of <b>F</b>, <b>A1</b> or <b>A2</b>
724                                throw an exception.</p>
725                </blockquote>
726                <h4><a name="bind_7_1">template&lt;class F, class A1, class A2&gt; <i>unspecified-7-1</i>
727                                bind(F f, A1 a1, A2 a2)</a></h4>
728                <blockquote>
729                        <p><b>Effects:</b> Equivalent to <tt>bind&lt;typename F::result_type, F, A1, A2&gt;(f,
730                                        a1, a2);</tt></p>
731                        <p><b>Notes:</b> Implementations are allowed to infer the return type of <b>f</b> via
732                                other means as an extension, without relying on the <tt>result_type</tt> member.</p>
733                </blockquote>
734                <h4><a name="bind_8">template&lt;class R, class B1, class B2, class A1, class A2&gt; <i>unspecified-8</i>
735                                bind(R (*f) (B1, B2), A1 a1, A2 a2)</a></h4>
736                <blockquote>
737                        <p><b>Returns:</b> A function object <i>&#955;</i> such that the expression <tt>&#955;(v<sub>1</sub>,
738                                        v<sub>2</sub>, ..., v<sub>m</sub>)</tt> is equivalent to <tt><b>f</b>(µ(<b>a1</b>,
739                                        v<sub>1</sub>, v<sub>2</sub>, ..., v<sub>m</sub>), µ(<b>a2</b>, v<sub>1</sub>,
740                                        v<sub>2</sub>, ..., v<sub>m</sub>))</tt>.</p>
741                        <p><b>Throws:</b> Nothing unless the copy constructors of <b>A1</b> or <b>A2</b> throw
742                                an exception.</p>
743                </blockquote>
744                <h4><a name="bind_9">template&lt;class R, class T, class B1, class A1, class A2&gt; <i>unspecified-9</i>
745                                bind(R (T::*f) (B1), A1 a1, A2 a2)</a></h4>
746                <blockquote>
747                        <p><b>Effects:</b> Equivalent to <tt>bind&lt;R&gt;(<A href="mem_fn.html">boost::mem_fn</A>(f),
748                                        a1, a2);</tt></p>
749                </blockquote>
750                <h4><a name="bind_10">template&lt;class R, class T, class B1, class A1, class A2&gt; <i>unspecified-10</i>
751                                bind(R (T::*f) (B1) const, A1 a1, A2 a2)</a></h4>
752                <blockquote>
753                        <p><b>Effects:</b> Equivalent to <tt>bind&lt;R&gt;(<A href="mem_fn.html">boost::mem_fn</A>(f),
754                                        a1, a2);</tt></p>
755                </blockquote>
756                <h3><a name="AdditionalOverloads">Additional overloads</a></h3>
757                <p>Implementations are allowed to provide additional <b>bind</b> overloads in order
758                        to support more arguments or different function pointer variations.</p>
759                <h2><a name="Implementation">Implementation</a></h2>
760                <h3><a name="Files">Files</a></h3>
761                <ul>
762                        <li>
763                                <A href="../../boost/bind.hpp">boost/bind.hpp</A>
764                        (main header)
765                        <li>
766                                <A href="../../boost/bind/bind_cc.hpp">boost/bind/bind_cc.hpp</A>
767                        (used by bind.hpp, do not include directly)
768                        <li>
769                                <A href="../../boost/bind/bind_mf_cc.hpp">boost/bind/bind_mf_cc.hpp</A>
770                        (used by bind.hpp, do not include directly)
771                        <li>
772                                <A href="../../boost/bind/bind_template.hpp">boost/bind/bind_template.hpp</A>
773                        (used by bind.hpp, do not include directly)
774                        <LI>
775                                <A href="../../boost/bind/arg.hpp">boost/bind/arg.hpp</A>
776                        (defines the type of the placeholder arguments)
777                        <LI>
778                                <A href="../../boost/bind/placeholders.hpp">boost/bind/placeholders.hpp</A>
779                        (defines the _1, _2, ... _9 placeholders)
780                        <LI>
781                                <A href="../../boost/bind/apply.hpp">boost/bind/apply.hpp</A> (<STRONG>apply</STRONG>
782                        helper function object)
783                        <LI>
784                                <A href="../../boost/bind/protect.hpp">boost/bind/protect.hpp</A> (<STRONG>protect</STRONG>
785                        helper function)
786                        <LI>
787                                <A href="../../boost/bind/make_adaptable.hpp">boost/bind/make_adaptable.hpp</A>
788                                (<STRONG>make_adaptable</STRONG>
789                        helper function)
790                        <li>
791                                <A href="test/bind_test.cpp">libs/bind/test/bind_test.cpp</A>
792                        (test)
793                        <li>
794                                <A href="bind_as_compose.cpp">libs/bind/bind_as_compose.cpp</A>
795                        (function composition example)
796                        <li>
797                                <A href="bind_visitor.cpp">libs/bind/bind_visitor.cpp</A>
798                        (visitor example)
799                        <li>
800                                <A href="test/bind_stdcall_test.cpp">libs/bind/test/bind_stdcall_test.cpp</A>
801                        (test with __stdcall functions)
802                        <li>
803                                <A href="test/bind_stdcall_mf_test.cpp">libs/bind/test/bind_stdcall_mf_test.cpp</A>
804                        (test with __stdcall member functions)
805                        <li>
806                                <A href="test/bind_fastcall_test.cpp">libs/bind/test/bind_fastcall_test.cpp</A>
807                        (test with __fastcall functions)
808                        <li>
809                                <A href="test/bind_fastcall_mf_test.cpp">libs/bind/test/bind_fastcall_mf_test.cpp</A>
810                                (test with __fastcall member functions)</li></ul>
811                <h3><a name="Dependencies">Dependencies</a></h3>
812                <ul>
813                        <li>
814                                <A href="../config/config.htm">Boost.Config</A>
815                        <li>
816                                <A href="ref.html">boost/ref.hpp</A>
817                        <li>
818                                <A href="mem_fn.html">boost/mem_fn.hpp</A>
819                        <li>
820                                <A href="../../boost/type.hpp">boost/type.hpp</A></li>
821                </ul>
822                <h3><a name="NumberOfArguments">Number of Arguments</a></h3>
823                <p>This implementation supports function objects with up to nine arguments. This is
824                        an implementation detail, not an inherent limitation of the design.</p>
825                <h3><a name="stdcall">"__stdcall", "__cdecl", "__fastcall", and "pascal" Support</a></h3>
826                <p>Some platforms allow several types of (member) functions that differ by their <b>calling
827                                convention</b> (the rules by which the function is invoked: how are
828                        arguments passed, how is the return value handled, and who cleans up the stack
829                        - if any.)</p>
830                <p>For example, Windows API functions and COM interface member functions use a
831                        calling convention known as <b>__stdcall</b>.Borland VCL components use <STRONG>__fastcall</STRONG>.
832                        Mac toolbox functions use a <b>pascal</b> calling convention.</p>
833                <p>To use <b>bind</b> with <b>__stdcall</b> functions, <b>#define</b> the macro <b>BOOST_BIND_ENABLE_STDCALL</b>
834                        before including <b>&lt;boost/bind.hpp&gt;</b>.</p>
835                <p>To use <b>bind</b> with <b>__stdcall</b> <b>member</b> functions, <b>#define</b>
836                        the macro <b>BOOST_MEM_FN_ENABLE_STDCALL</b> before including <b>&lt;boost/bind.hpp&gt;</b>.</p>
837                <P>To use <B>bind</B> with <B>__fastcall</B> functions, <B>#define</B> the macro <B>BOOST_BIND_ENABLE_FASTCALL</B>
838                        before including <B>&lt;boost/bind.hpp&gt;</B>.</P>
839                <P>To use <B>bind</B> with <B>__fastcall</B> <B>member</B> functions, <B>#define</B>
840                        the macro <B>BOOST_MEM_FN_ENABLE_FASTCALL</B> before including <B>&lt;boost/bind.hpp&gt;</B>.</P>
841                <P>To use <b>bind</b> with <b>pascal</b> functions, <b>#define</b> the macro <b>BOOST_BIND_ENABLE_PASCAL</b>
842                        before including <b>&lt;boost/bind.hpp&gt;</b>.</P>
843                <P>To use <B>bind</B> with <B>__cdecl</B> <B>member</B> functions, <B>#define</B> the
844                        macro <B>BOOST_MEM_FN_ENABLE_CDECL</B> before including <B>&lt;boost/bind.hpp&gt;</B>.</P>
845                <P><STRONG>It is best to define these macros in the project options, via -D on the
846                                command line, or as the first line in the translation unit (.cpp file) where
847                                bind is used.</STRONG> Not following this rule can lead to obscure errors
848                        when a header includes bind.hpp before the macro has been defined.</P>
849                <p>[Note: this is a non-portable extension. It is not part of the interface.]</p>
850                <p>[Note: Some compilers provide only minimal support for the <b>__stdcall</b> keyword.]</p>
851                <h3><a name="visit_each"><b>visit_each</b> support</a></h3>
852                <p>Function objects returned by <b>bind</b> support the experimental and
853                        undocumented, as of yet, <b>visit_each</b> enumeration interface.</p>
854                <p>See <A href="bind_visitor.cpp">bind_visitor.cpp</A> for an example.</p>
855                <h2><a name="Acknowledgements">Acknowledgements</a></h2>
856                <p>Earlier efforts that have influenced the library design:</p>
857                <ul>
858                        <li>
859                                The <a href="http://staff.cs.utu.fi/BL/">Binder Library</a>
860                        by Jaakko Järvi;
861                        <li>
862                                The <a href="../lambda/index.html">Lambda Library</a>
863                        (now part of Boost) by Jaakko Järvi and Gary Powell (the successor to the
864                        Binder Library);
865                        <li>
866                                <a href="http://more.sourceforge.net/">Extensions to the
867                                        STL</a> by Petter Urkedal.</li></ul>
868                <p>Doug Gregor suggested that a visitor mechanism would allow <b>bind</b> to
869                        interoperate with a signal/slot library.</p>
870                <p>John Maddock fixed a MSVC-specific conflict between <b>bind</b> and the <A href="../type_traits/index.html">
871                                type traits library</A>.</p>
872                <p>Numerous improvements were suggested during the formal review period by Ross
873                        Smith, Richard Crossley, Jens Maurer, Ed Brey, and others. Review manager was
874                        Darin Adler.
875                </p>
876                <p>The precise semantics of <b>bind</b> were refined in discussions with Jaakko
877                        Järvi.
878                </p>
879                <p>Dave Abrahams fixed a MSVC-specific conflict between <b>bind</b> and the <A href="../utility/iterator_adaptors.htm">
880                                iterator adaptors library</A>.
881                </p>
882                <p>Dave Abrahams modified <b>bind</b> and <b>mem_fn</b> to support void returns on
883                        deficient compilers.
884                </p>
885                <p>Mac Murrett contributed the "pascal" support enabled by
886                        BOOST_BIND_ENABLE_PASCAL.
887                </p>
888                <p>The alternative <tt>bind(type&lt;R&gt;(), f, ...)</tt> syntax was inspired by a
889                        discussion with Dave Abrahams and Joel de Guzman.</p>
890                <p><br>
891                        <br>
892                        <br>
893                        <small>Copyright © 2001, 2002 by Peter Dimov and Multi Media Ltd. Copyright
894                                2003-2005 Peter Dimov. Permission to copy, use, modify, sell and distribute
895                                this document is granted provided this copyright notice appears in all copies.
896                                This document is provided "as is" without express or implied warranty, and with
897                                no claim as to its suitability for any purpose.</small></p>
898        </body>
899</html>
Note: See TracBrowser for help on using the repository browser.