mirror of
https://github.com/boostorg/function.git
synced 2025-07-29 20:37:14 +02:00
tutorial.xml: Add short discussion of the comparison of Boost.Function
objects to function objects. [SVN r21904]
This commit is contained in:
@ -274,7 +274,7 @@ f(&x, 5);</programlisting>
|
|||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<title>References to Functions</title> <para> In some cases it is
|
<title>References to Function Objects</title> <para> In some cases it is
|
||||||
expensive (or semantically incorrect) to have Boost.Function clone a
|
expensive (or semantically incorrect) to have Boost.Function clone a
|
||||||
function object. In such cases, it is possible to request that
|
function object. In such cases, it is possible to request that
|
||||||
Boost.Function keep only a reference to the actual function
|
Boost.Function keep only a reference to the actual function
|
||||||
@ -321,5 +321,37 @@ using references to function objects, Boost.Function will not throw
|
|||||||
exceptions during assignment or construction.
|
exceptions during assignment or construction.
|
||||||
</para>
|
</para>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<title>Comparing Boost.Function function objects</title>
|
||||||
|
|
||||||
|
<para>Function object wrappers can be compared via <code>==</code>
|
||||||
|
or <code>!=</code> against any function object that can be stored
|
||||||
|
within the wrapper. If the function object wrapper contains a
|
||||||
|
function object of that type, it will be compared against the given
|
||||||
|
function object (which must be
|
||||||
|
<conceptname>EqualityComparable</conceptname>). For instance:</para>
|
||||||
|
|
||||||
|
<programlisting name="function.tutorial.compare">int compute_with_X(X*, int);
|
||||||
|
|
||||||
|
f = &X::foo;
|
||||||
|
assert(f == &X::foo);
|
||||||
|
assert(&compute_with_X != f);</programlisting>
|
||||||
|
|
||||||
|
<para>When comparing against an instance of
|
||||||
|
<code><classname>reference_wrapper</classname></code>, the address
|
||||||
|
of the object in the
|
||||||
|
<code><classname>reference_wrapper</classname></code> is compared
|
||||||
|
against the address of the object stored by the function object
|
||||||
|
wrapper:</para>
|
||||||
|
|
||||||
|
<programlisting name="function.tutorial.compare-ref">a_stateful_object so1, so2;
|
||||||
|
f = <functionname>boost::ref</functionname>(so1);
|
||||||
|
assert(f == <functionname>boost::ref</functionname>(so1));
|
||||||
|
assert(f == so1); <emphasis>// Only if a_stateful_object is <conceptname>EqualityComparable</conceptname></emphasis>
|
||||||
|
assert(f != <functionname>boost::ref</functionname>(so2));</programlisting>
|
||||||
|
|
||||||
|
</section>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user