forked from boostorg/bind
23
bind.html
23
bind.html
@@ -188,6 +188,27 @@ bind(std::less<int>(), _1, 9)(x); // x < 9
|
|||||||
</pre>
|
</pre>
|
||||||
<p>[Note: the ability to omit the return type is not available on all compilers.]
|
<p>[Note: the ability to omit the return type is not available on all compilers.]
|
||||||
</p>
|
</p>
|
||||||
|
<P>By default, <STRONG>bind</STRONG> makes a copy of the provided function object. <code>
|
||||||
|
boost::ref</code> and <code>boost::cref</code> can be used to make it store
|
||||||
|
a reference to the function object, rather than a copy. This can be useful when
|
||||||
|
the function object is noncopyable, expensive to copy, or contains state; of
|
||||||
|
course, in this case the programmer is expected to ensure that the function
|
||||||
|
object is not destroyed while it's still being used.</P>
|
||||||
|
<pre>struct F2
|
||||||
|
{
|
||||||
|
int s;
|
||||||
|
|
||||||
|
typedef void result_type;
|
||||||
|
void operator()( int x ) { s += x; }
|
||||||
|
};
|
||||||
|
|
||||||
|
F2 f2 = { 0 };
|
||||||
|
int a[] = { 1, 2, 3 };
|
||||||
|
|
||||||
|
std::for_each( a, a+3, bind( ref(f2), _1 ) );
|
||||||
|
|
||||||
|
assert( f2.s == 6 );
|
||||||
|
</pre>
|
||||||
<h3><a name="with_member_pointers">Using bind with pointers to members</a></h3>
|
<h3><a name="with_member_pointers">Using bind with pointers to members</a></h3>
|
||||||
<p>Pointers to member functions and pointers to data members are not function
|
<p>Pointers to member functions and pointers to data members are not function
|
||||||
objects, because they do not support <tt>operator()</tt>. For convenience, <b>bind</b>
|
objects, because they do not support <tt>operator()</tt>. For convenience, <b>bind</b>
|
||||||
@@ -890,7 +911,7 @@ namespace
|
|||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<small>Copyright <20> 2001, 2002 by Peter Dimov and Multi Media Ltd. Copyright
|
<small>Copyright <20> 2001, 2002 by Peter Dimov and Multi Media Ltd. Copyright
|
||||||
2003-2005 Peter Dimov. Distributed under the Boost Software License, Version
|
2003-2008 Peter Dimov. Distributed under the Boost Software License, Version
|
||||||
1.0. See accompanying file <A href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</A> or
|
1.0. See accompanying file <A href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</A> or
|
||||||
copy at <A href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</A>.</small></p>
|
copy at <A href="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</A>.</small></p>
|
||||||
</body>
|
</body>
|
||||||
|
Reference in New Issue
Block a user