forked from boostorg/bind
Section on operators.
[SVN r27680]
This commit is contained in:
24
bind.html
24
bind.html
@@ -27,6 +27,7 @@
|
||||
to members</A></h4>
|
||||
<h4 style="MARGIN-LEFT: 40pt"><A href="#nested_binds">Using nested binds for function
|
||||
composition</A></h4>
|
||||
<h4 style="MARGIN-LEFT: 40pt"><A href="#operators">Overloaded operators</A></h4>
|
||||
<h3 style="MARGIN-LEFT: 20pt"><A href="#Examples">Examples</A></h3>
|
||||
<h4 style="MARGIN-LEFT: 40pt"><A href="#with_algorithms">Using bind with standard
|
||||
algorithms</A></h4>
|
||||
@@ -280,6 +281,29 @@ std::for_each(v.begin(), v.end(), bind(apply<void>(), _1, 5));
|
||||
<P>The header <STRONG>boost/bind/protect.hpp</STRONG> contains an implementation of <STRONG>
|
||||
protect</STRONG>. To protect a <STRONG>bind</STRONG> function object from
|
||||
evaluation, use <tt>protect(bind(f, ...))</tt>.</P>
|
||||
<h3><a name="operators">Overloaded operators</a> (new in Boost 1.34)</h3>
|
||||
<p>For convenience, the function objects produced by <tt>bind</tt> overload
|
||||
the logical not operator <STRONG>!</STRONG> and the relational operators <STRONG>==</STRONG>,
|
||||
<STRONG>!=</STRONG>, <STRONG><</STRONG>, <STRONG><=</STRONG>, <STRONG>></STRONG>,
|
||||
<STRONG>>=</STRONG>.</p>
|
||||
<P><tt>!bind(f, ...)</tt> is equivalent to <tt>bind( <EM>logical_not</EM>(), bind(f,
|
||||
...) )</tt>, where <tt><EM>logical_not</EM></tt> is a function object that
|
||||
takes one argument <tt>x</tt> and returns <tt>!x</tt>.</P>
|
||||
<P><tt>bind(f, ...) <EM>op</EM> x</tt>, where <EM>op</EM> is a relational operator,
|
||||
is equivalent to <tt>bind( <EM>relation</EM>(), bind(f, ...), x )</tt>, where <em>relation</em>
|
||||
is a function object that takes two arguments <tt>a</tt> and <tt>b</tt> and
|
||||
returns <tt>a <EM>op</EM> b</tt>.</P>
|
||||
<P>What this means in practice is that you can conveniently negate the result of
|
||||
<tt>bind</tt>:</P>
|
||||
<P><tt>std::remove_if( first, last, !bind( &X::visible, _1 ) ); // remove invisible
|
||||
objects</tt></P>
|
||||
<P>and compare the result of <tt>bind</tt> against a value:</P>
|
||||
<P><tt>std::find_if( first, last, bind( &X::name, _1 ) == "peter" );</tt></P>
|
||||
<P>against a placeholder:</P>
|
||||
<P><tt>bind( &X::name, _1 ) == _2</tt></P>
|
||||
<P>or against another <tt>bind</tt> expression:</P>
|
||||
<P><tt>std::sort( first, last, bind( &X::name, _1 ) < bind( &X::name, _2 )
|
||||
); // sort by name</tt></P>
|
||||
<h2><a name="Examples">Examples</a></h2>
|
||||
<h3><a name="with_algorithms">Using bind with standard algorithms</a></h3>
|
||||
<pre>class image;
|
||||
|
Reference in New Issue
Block a user