Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r66973 - trunk/libs/bind
From: marshall_at_[hidden]
Date: 2010-12-02 08:17:14


Author: marshall
Date: 2010-12-02 08:17:09 EST (Thu, 02 Dec 2010)
New Revision: 66973
URL: http://svn.boost.org/trac/boost/changeset/66973

Log:
Doc patch; refs #4532
Text files modified:
   trunk/libs/bind/bind.html | 43 ++++++++++++++++++++++++++++++++++++++++
   1 files changed, 43 insertions(+), 0 deletions(-)

Modified: trunk/libs/bind/bind.html
==============================================================================
--- trunk/libs/bind/bind.html (original)
+++ trunk/libs/bind/bind.html 2010-12-02 08:17:09 EST (Thu, 02 Dec 2010)
@@ -61,6 +61,7 @@
                                 bind&lt;R&gt;(f, ...)</A></h4>
                 <h4 style="MARGIN-LEFT: 40pt">Binding a nonstandard function</h4>
                 <h4 style="MARGIN-LEFT: 40pt">Binding an overloaded function</h4>
+ <h4 style="MARGIN-LEFT: 40pt">Modeling STL function object concepts</h4>
                 <h4 style="MARGIN-LEFT: 40pt">const in signatures</h4>
                 <h4 style="MARGIN-LEFT: 40pt"><A href="#err_msvc_using">MSVC specific: using
                                 boost::bind;</A></h4>
@@ -585,6 +586,48 @@
     boost::bind( get, _1 );
 }
 </pre>
+ <h3><a name="err_modeling_stl_function_object_concepts">Modeling STL function object concepts</a></h3>
+ <p>The function objects that are produced by <b>boost::bind</b> do not model the
+ STL Unary Function or
+ Binary Function concepts,
+ even when the function objects are unary or binary operations, because the function object
+ types are missing public typedefs <tt>result_type</tt> and <tt>argument_type</tt> or
+ <tt>first_argument_type</tt> and <tt>second_argument_type</tt>. In cases where these
+ typedefs are desirable, however, the utility function <tt>make_adaptable</tt>
+ can be used to adapt unary and binary function objects to these concepts. This allows
+ unary and binary function objects resulting from <b>boost::bind</b> to be combined with
+ STL templates such as std::unary_negate
+ and std::binary_negate.</p>
+
+ <p>The <tt>make_adaptable</tt> function is defined in &lt;boost/bind/make_adaptable.hpp&gt;,
+ which must be included explicitly in addition to &lt;boost/bind.hpp&gt;:</p>
+ <pre>
+#include &lt;boost/bind/make_adaptable.hpp&gt;
+
+template &lt;class R, class F&gt; <i>unspecified-type</i> make_adaptable(F f);
+
+template&lt;class R, class A1, class F&gt; <i>unspecified-unary-functional-type</i> make_adaptable(F f);
+
+template&lt;class R, class A1, class A2, class F&gt; <i>unspecified-binary-functional-type</i> make_adaptable(F f);
+
+template&lt;class R, class A1, class A2, class A3, class F&gt; <i>unspecified-ternary-functional-type</i> make_adaptable(F f);
+
+template&lt;class R, class A1, class A2, class A3, class A4, class F&gt; <i>unspecified-4-ary-functional-type</i> make_adaptable(F f);
+ </pre>
+
+ <p>This example shows how to use <tt>make_adaptable</tt> to make a predicate for "is not a space":</p>
+ <pre>typedef char char_t;
+std::locale loc("");
+const std::ctype&lt;char_t&gt;&amp; ct = std::use_facet&lt;std::ctype&lt;char_t&gt; &gt;(loc);
+
+auto isntspace = std::not1( boost::make_adaptable&lt;bool, char_t&gt;( boost::bind(&amp;std::ctype&lt;char_t&gt;::is, &amp;ct, std::ctype_base::space, _1) ) );
+</pre>
+
+ <p>In this example, <b>boost::bind</b> creates the "is a space" (unary) predicate.
+ It is then passed to <tt>make_adaptable</tt> so that a function object modeling
+ the Unary Function concept can be created, serving as the argument to
+ std::not1.</p>
+
                 <h3><a name="err_const_arg"><b>const</b> in signatures</a></h3>
                 <p>Some compilers, including MSVC 6.0 and Borland C++ 5.5.1, have problems with the
                         top-level <b>const</b> in function signatures:


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk