Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r67047 - branches/release/libs/bind
From: marshall_at_[hidden]
Date: 2010-12-05 17:18:13

Author: marshall
Date: 2010-12-05 17:18:05 EST (Sun, 05 Dec 2010)
New Revision: 67047

Merge doc fix to release; fixes #4532
Text files modified:
   branches/release/libs/bind/bind.html | 43 ++++++++++++++++++++++++++++++++++++++++
   1 files changed, 43 insertions(+), 0 deletions(-)

Modified: branches/release/libs/bind/bind.html
--- branches/release/libs/bind/bind.html (original)
+++ branches/release/libs/bind/bind.html 2010-12-05 17:18:05 EST (Sun, 05 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
@@ -585,6 +586,48 @@
     boost::bind( get, _1 );
+ <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) ) );
+ <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, david.abrahams at, gregod at, cpdaniel at, john at