forked from boostorg/functional
Initial HTML commit
[SVN r7636]
This commit is contained in:
+184
@@ -0,0 +1,184 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
|
||||
<meta name="ProgId" content="FrontPage.Editor.Document">
|
||||
<title>Boost Function Object Adapter Library</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF" text="#000000">
|
||||
|
||||
<table border="1" bgcolor="#007F7F" cellpadding="2">
|
||||
<tr>
|
||||
<td bgcolor="#FFFFFF"><img src="../../c++boost.gif" alt="c++boost.gif (8819 bytes)" width="277" height="86"></td>
|
||||
<td><a href="../../index.htm"><font face="Arial" color="#FFFFFF"><big>Home</big></font></a></td>
|
||||
<td><a href="../../libraries.htm"><font face="Arial" color="#FFFFFF"><big>Libraries</big></font></a></td>
|
||||
<td><a href="../../people.htm"><font face="Arial" color="#FFFFFF"><big>People</big></font></a></td>
|
||||
<td><a href="../../more/faq.htm"><font face="Arial" color="#FFFFFF"><big>FAQ</big></font></a></td>
|
||||
<td><a href="../../more/index.htm"><font face="Arial" color="#FFFFFF"><big>More</big></font></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<h1>Improved Function Object Adapters</h1>
|
||||
<p>The header <nobr><a href="../../boost/functional.hpp">functional.hpp</a></nobr>
|
||||
provides enhancements to the function object adapters specified in the C++
|
||||
Standard Library (sections 20.3.5, through to 20.3.8). The enhancements are
|
||||
principally possible due to two changes:</p>
|
||||
<ol>
|
||||
<li>We use the Boost <nobr><tt><a href="../utility/call_traits.htm">call_traits</a></tt></nobr>
|
||||
templates to avoid the problem of <a href="binders.html#refref">references
|
||||
to references</a>, and to improve the efficiency of <a href="mem_fun.html#args">parameter
|
||||
passing</a>.</li>
|
||||
<li>We use two <a href="function_traits.html">function object traits</a> class
|
||||
templates to avoid the need for <nobr><tt><a href="ptr_fun.html">ptr_fun</a></tt></nobr>
|
||||
with the adapters in this library.</li>
|
||||
</ol>
|
||||
<h3>Contents</h3>
|
||||
<p>The header contains the following function and class templates:</p>
|
||||
<table border="1" cellpadding="5">
|
||||
<tr>
|
||||
<th align="left"><a href="function_traits.html">Function object traits</a>
|
||||
<td valign="top"><tt><nobr>unary_traits</nobr><br>
|
||||
<nobr>binary_traits</nobr></tt></td>
|
||||
<td valign="top">Used to determine the types of function objects' and
|
||||
functions' arguments. Eliminate the necessity for <nobr><tt>ptr_fun</tt></nobr>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th align="left"><a href="negators.html">Negators</a></th>
|
||||
<td valign="top"><tt><nobr>unary_negate</nobr><br>
|
||||
<nobr>binary_negate</nobr><br>
|
||||
<nobr>not1</nobr><br>
|
||||
<nobr>not2</nobr></tt></td>
|
||||
<td valign="top">Based on section 20.3.5 of the standard.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th align="left"><a href="binders.html">Binders</a></th>
|
||||
<td valign="top"><tt><nobr>binder1st</nobr><br>
|
||||
<nobr>binder2nd</nobr><br>
|
||||
<nobr>bind1st</nobr><br>
|
||||
<nobr>bind2nd</nobr></tt></td>
|
||||
<td valign="top">Based on section 20.3.6 of the standard.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th align="left"><a href="ptr_fun.html">Adapters for pointers to functions</a></th>
|
||||
<td valign="top"><tt><nobr>pointer_to_unary_function</nobr><br>
|
||||
<nobr>pointer_to_binary_function</nobr><br>
|
||||
<nobr>ptr_fun</nobr></tt></td>
|
||||
<td valign="top">Based on section 20.3.7 of the standard. Not required for
|
||||
use with this library since the binders and negators can adapt functions,
|
||||
but may be needed with third party adapters.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th align="left"><a href="mem_fun.html">Adapters for pointers to member
|
||||
functions</a></th>
|
||||
<td valign="top"><tt><nobr>mem_fun_t</nobr><br>
|
||||
<nobr>mem_fun1_t</nobr><br>
|
||||
<nobr>const_mem_fun_t</nobr><br>
|
||||
<nobr>const_mem_fun1_t</nobr><br>
|
||||
<nobr>mem_fun_ref_t</nobr><br>
|
||||
<nobr>mem_fun1_ref_t</nobr><br>
|
||||
<nobr>const_mem_fun_ref_t</nobr><br>
|
||||
<nobr>const_mem_fun1_ref_t</nobr><br>
|
||||
<nobr>mem_fun</nobr><br>
|
||||
<nobr>mem_fun_ref</nobr></tt></td>
|
||||
<td valign="top">Based on section 20.3.8 of the standard.</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h3>Usage</h3>
|
||||
<p>Using these adapters should be pretty much the same as using the standard
|
||||
function object adapters; the only differences are that you need to write <nobr><tt>boost::</tt></nobr>
|
||||
instead of <nobr><tt>std::</tt></nobr>, and that you will get fewer headaches.</p>
|
||||
<p>For example, suppose you had a <tt>Person</tt> class that contained a <nobr><tt>set_name</tt></nobr>
|
||||
function:
|
||||
<blockquote>
|
||||
<pre>
|
||||
class Person
|
||||
{
|
||||
public:
|
||||
void set_name(const std::string &name);
|
||||
// ...
|
||||
};
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>You could rename a bunch of people in a collection, <tt>c</tt>, by writing</p>
|
||||
<blockquote>
|
||||
<pre>
|
||||
std::for_each(c.begin(), c.end(),
|
||||
boost::bind2nd(boost::mem_fun_ref(&Person::set_name), "Fred"));
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>If the standard adapters had been used instead then this code would normally
|
||||
fail to compile, because <tt><nobr>set_name</nobr></tt> takes a reference
|
||||
argument. Refer to the comments in the <a href="binders.html#refref">binder
|
||||
documentation</a> to explain why this is so.</p>
|
||||
<h3>Compiler Compatibility</h3>
|
||||
<p>The header and <a href="function_test.cpp">test program</a> have been
|
||||
compiled with the following compilers:</p>
|
||||
<table border="1" cellpadding="5">
|
||||
<tr>
|
||||
<th>Compiler</th>
|
||||
<th>Comments</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top">Borland C++Builder 4 Update 2</td>
|
||||
<td valign="top">No known issues.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top">Borland C++ 5.5</td>
|
||||
<td valign="top">No known issues.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top">g++ 2.95.2</td>
|
||||
<td valign="top">No known issues.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="top">Microsoft Visual C++ Service Pack 3</td>
|
||||
<td valign="top">Compiler lacks partial specialisation, so this library
|
||||
offers little more than is provided by the standard adapters:
|
||||
<ul>
|
||||
<li>The <nobr><tt>call_traits</tt></nobr> mechanism is unable to prevent
|
||||
references to references, and so the adapters in this library will be
|
||||
usable in fewer situations.</li>
|
||||
<li>The <nobr><tt>function_traits</tt></nobr> mechanism is unable to
|
||||
determine the argument and result types of functions, therefore <nobr><tt>ptr_fun</tt></nobr>
|
||||
continues to be required to adapt functions.
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h3>Future Directions</h3>
|
||||
<p>This library's primary focus is to solve the problem of references to
|
||||
references while maintaining as much compatibility as possible with the standard
|
||||
library. This allows you to use the techniques you read about in books and
|
||||
magazines with many of today's compilers.</p>
|
||||
<p>In the longer term, even better solutions are likely:</p>
|
||||
<ol>
|
||||
<li>Several Boost members are working on expression template libraries. These
|
||||
will allow a more natural syntax for combining and adapting functions. As
|
||||
this is a new technology, it may be some time before it has matured and is
|
||||
widely supported by major compilers but shows great promise. In the
|
||||
meantime, the functional.hpp library fills the gap.</li>
|
||||
<li>The Standard Committee has recognised the problem of references to
|
||||
references occurring during template instantiation and has moved to fix the
|
||||
standard (see the <a href="http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html#106">C++
|
||||
standard core language active issues list</a>).</li>
|
||||
</ol>
|
||||
<h3>Author</h3>
|
||||
<p><a href="../../people/mark_rodgers.htm">Mark Rodgers</a></p>
|
||||
<h3>Acknowledgements</h3>
|
||||
<p>Thanks to <a href="../../people/john_maddock.htm">John Maddock</a> for
|
||||
suggesting the mechanism that allowed the function objects traits to work
|
||||
correctly. <a href="../../people/jens_maurer.htm">Jens Maurer</a> provided
|
||||
invaluable feedback during the <a href="../../more/formal_review_process.htm">formal
|
||||
review process</a>.
|
||||
<hr>
|
||||
<p>Copyright © 2000 Cadenza New Zealand Ltd. Permission to copy, use, modify,
|
||||
sell and distribute this document is granted provided this copyright notice
|
||||
appears in all copies. This document is provided "as is" without
|
||||
express or implied warranty, and with no claim as to its suitability for any
|
||||
purpose.</p>
|
||||
<p>Revised 28 June 2000</p>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user