template<class R, class F, class A1><i>implementation-defined-3</i><ahref="#bind_3">bind</a>(F f, A1 a1);
template<class R, class B1, class A1><i>implementation-defined-4</i><ahref="#bind_4">bind</a>(R (*f) (B1), A1 a1);
template<class R, class T, class A1><i>implementation-defined-5</i><ahref="#bind_5">bind</a>(R (T::*f) (), A1 a1);
template<class R, class T, class A1><i>implementation-defined-6</i><ahref="#bind_6">bind</a>(R (T::*f) () const, A1 a1);
// two arguments
template<class R, class F, class A1, class A2><i>implementation-defined-7</i><ahref="#bind_7">bind</a>(F f, A1 a1, A2 a2);
template<class R, class B1, class B2, class A1, class A2><i>implementation-defined-8</i><ahref="#bind_8">bind</a>(R (*f) (B1, B2), A1 a1, A2 a2);
template<class R, class T, class B1, class A1, class A2><i>implementation-defined-9</i><ahref="#bind_9">bind</a>(R (T::*f) (B1), A1 a1, A2 a2);
template<class R, class T, class B1, class A1, class A2><i>implementation-defined-10</i><ahref="#bind_10">bind</a>(R (T::*f) (B1) const, A1 a1, A2 a2);
// implementation defined number of additional overloads for more arguments
<b>Throws:</b> Nothing unless the copy constructors of <b>F</b>, <b>A1</b> and <b>A2</b> throw an exception.
</p>
<h4><aname="bind_8">template<class R, class B1, class B2, class A1, class A2><i>implementation-defined-8</i> bind(R (*f) (B1, B2), A1 a1, A2 a2)</a></h4>
<p>
<b>Returns:</b> a function object <i>λ</i> such that the expression
<tt>λ(v<sub>1</sub>, v<sub>2</sub>, ..., v<sub>m</sub>)</tt> is equivalent to
<b>Throws:</b> Nothing unless the copy constructors of <b>A1</b> and <b>A2</b> throw an exception.
</p>
<h4><aname="bind_9">template<class R, class T, class B1, class A1, class A2><i>implementation-defined-9</i> bind(R (T::*f) (B1), A1 a1, A2 a2)</a></h4>
<p>
<b>Effects:</b> equivalent to <tt>bind<R>(<ahref="mem_fn.html">boost::mem_fn</a>(f), a1, a2);</tt>
</p>
<h4><aname="bind_10">template<class R, class T, class B1, class A1, class A2><i>implementation-defined-10</i> bind(R (T::*f) (B1) const, A1 a1, A2 a2)</a></h4>
<p>
<b>Effects:</b> equivalent to <tt>bind<R>(<ahref="mem_fn.html">boost::mem_fn</a>(f), a1, a2);</tt>
</p>
<h2>Implementation</h2>
<p>
This implementation supports function objects with up to nine arguments.
This is an implementation detail, not an inherent limitation of the
design.
</p>
<h3>Void returns</h3>
<p>
The following C++ code:
</p>
<pre>
void f();
void g()
{
return f();
}
</pre>
<p>
is legal; in fact it was deliberately made legal in order to support
forwarding functions that return <b>void</b>.
</p>
<p>
Unfortunately, some compilers have not caught up with the C++ Standard yet
and do not allow void returns. This implementation of <b>bind</b> will not
work for function pointers, member function pointers or function objects that
return <b>void</b> if the compiler does not support the feature. A possible
workaround is to change the return type of the function object in question
from <b>void</b> to <b>int</b> and return a dummy value of 0.
</p>
<h3>MSVC specific problems and workarounds</h3>
<p>
Microsoft Visual C++ (up to version 7.0) does not fully support the
<b>bind<R>(...)</b>
syntax required by the library when arbitrary function objects are bound.
The first problem is that when <b>boost::bind</b> is brought into scope
with an <b>using declaration</b>:
</p>
<pre>
using boost::bind;
</pre>
<p>
the syntax above does not work. Workaround: either use the qualified name,
<b>boost::bind</b>, or use an <b>using directive</b> instead:
</p>
<pre>
using namespace boost;
</pre>
<p>
The second problem is that some libraries contain nested class templates
named <b>bind</b> (ironically, such code is often an MSVC specific
workaround.) Due to some quirks with the parser, such a class template
breaks the <b>bind<R>(...)</b> syntax, even when the name <b>bind</b>
is fully qualified. You may try to patch the library in question or contact
its author/maintainer. The other option is to define the macro
<b>BOOST_BIND</b> to something other than <b>bind</b> (before the inclusion of
<b><boost/bind.hpp></b>) and use this identifier throughout your code
wherever you'd normally use <b>bind</b>.
</p>
<pstyle="color: Red;">
[Note: BOOST_BIND is not a general renaming mechanism. It is not part of the
interface, and is not guaranteed to work on other compilers, or persist between
library versions. In short, don't use it unless you absolutely have to.]
</p>
<h3>Visitor support</h3>
<pstyle="color: Red;">
[Note: this is an experimental feature. It may evolve over time
when other libraries start to exploit it; or it may be removed altogether if
no other library needs it. It is not part of the interface.]
</p>
<p>
For better integration with other libraries, the function objects returned by
<b>bind</b> define a member function
</p>
<pre>
template<class Visitor> void accept(Visitor & v);
</pre>
<p>
that applies <b>v</b>, as a function object, to its internal state. Using
<b>accept</b> is implementation-specific and not intended for end users.
</p>
<p>
See <ahref="bind_test_4.cpp">bind_test_4.cpp</a> for an example.
</p>
<h2>Acknowledgements</h2>
<p>
Earlier efforts that have influenced the library design: