Merged L & C issue fixes from trunk to branch.

[SVN r36246]
This commit is contained in:
Andreas Huber
2006-12-02 14:17:26 +00:00
parent a2202df1fe
commit d2b04d968c
8 changed files with 990 additions and 697 deletions

View File

@ -1,132 +1,161 @@
<html> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Language" content="en-us">
<title>Boost Function Object Adapter Library</title> <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<title>Boost Function Object Adapter Library</title>
</head> </head>
<body bgcolor="#FFFFFF" text="#000000"> <body bgcolor="#FFFFFF" text="#000000">
<table border="1" bgcolor="#007F7F" cellpadding="2" summary="">
<tr>
<td bgcolor="#FFFFFF"><img src="../../boost.png" alt=
"boost.png (6897 bytes)" width="277" height="86"></td>
<table border="1" bgcolor="#007F7F" cellpadding="2"> <td><a href="../../index.htm"><font face="Arial" color=
<tr> "#FFFFFF"><big>Home</big></font></a></td>
<td bgcolor="#FFFFFF"><img src="../../boost.png" alt="boost.png (6897 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/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>Binders</h1> <td><a href="../libraries.htm"><font face="Arial" color=
"#FFFFFF"><big>Libraries</big></font></a></td>
<p>The header <nobr><a <td><a href="../../people/people.htm"><font face="Arial" color=
href="../../boost/functional.hpp">functional.hpp</a></nobr> provides "#FFFFFF"><big>People</big></font></a></td>
enhanced versions of both the binder function object adapters from the
C++ Standard Library <nobr>(&sect;20.3.6):</nobr></p>
<ul> <td><a href="../../more/faq.htm"><font face="Arial" color=
<li><tt>binder1st</tt></li> "#FFFFFF"><big>FAQ</big></font></a></td>
<li><tt>binder2nd</tt></li>
</ul>
<p>As well as the corresponding helper functions</p> <td><a href="../../more/index.htm"><font face="Arial" color=
"#FFFFFF"><big>More</big></font></a></td>
</tr>
</table>
<ul> <h1>Binders</h1>
<li><tt>bind1st</tt></li>
<li><tt>bind2nd</tt></li>
</ul>
<p>The key benefit of these adapters over those in the Standard <p>The header <a href="../../boost/functional.hpp">functional.hpp</a>
Library is they avoid the problem of <a href="#refref">references to provides enhanced versions of both the binder function object adapters from
references.</a> the C++ Standard Library (&sect;20.3.6):</p>
<h3>Usage</h3> <ul>
<li><tt>binder1st</tt></li>
<p>Usage is identical to the standard binders. For example,</p> <li><tt>binder2nd</tt></li>
</ul>
<blockquote><pre> <p>As well as the corresponding helper functions</p>
<ul>
<li><tt>bind1st</tt></li>
<li><tt>bind2nd</tt></li>
</ul>
<p>The key benefit of these adapters over those in the Standard Library is
they avoid the problem of <a href="#refref">references to
references.</a></p>
<h3>Usage</h3>
<p>Usage is identical to the standard binders. For example,</p>
<blockquote>
<pre>
class Foo { class Foo {
public: public:
void bar(std::ostream &); void bar(std::ostream &amp;);
// ... // ...
}; };
// ... // ...
std::vector&lt;Foo&gt; c; std::vector&lt;Foo&gt; c;
// ... // ...
std::for_each(c.begin(), c.end(), std::for_each(c.begin(), c.end(),
boost::bind2nd(boost::mem_fun_ref(&Foo::bar), std::cout)); boost::bind2nd(boost::mem_fun_ref(&amp;Foo::bar), std::cout));
</pre></blockquote> </pre>
</blockquote>
<h3 id="refref">References to References</h3> <h3 id="refref">References to References</h3>
<p>Consider the usage example above</p> <p>Consider the usage example above</p>
<blockquote><pre> <blockquote>
<pre>
class Foo { class Foo {
public: public:
void bar(<strong>std::ostream &</strong>); void bar(<strong>std::ostream &amp;</strong>);
// ... // ...
}; };
// ... // ...
std::for_each(c.begin(), c.end(), std::for_each(c.begin(), c.end(),
boost::bind2nd(boost::mem_fun_ref(&Foo::bar), std::cout)); boost::bind2nd(boost::mem_fun_ref(&amp;Foo::bar), std::cout));
</pre></blockquote> </pre>
</blockquote>
<p>If this had been written using <tt><nobr>std::bind2nd</nobr></tt> <p>If this had been written using <tt>std::bind2nd</tt> and
and <tt><nobr>std::mem_fun_ref</nobr></tt>, it would be unlikely to <tt>std::mem_fun_ref</tt>, it would be unlikely to compile.</p>
compile.</p>
<p>The problem arises because <tt><nobr>bar</nobr></tt> takes a <p>The problem arises because <tt>bar</tt> takes a reference argument. The
reference argument. The Standard defines Standard defines <tt>std::mem_fun_ref</tt> such that it creates a function
<tt><nobr>std::mem_fun_ref</nobr></tt> such that it creates a function object whose <tt>second_argument_type</tt> will be
object whose <tt><nobr>second_argument_type</nobr></tt> will be <tt>std::ostream&amp;</tt>.</p>
<tt><nobr>std::ostream&</nobr></tt>.</p>
<p>The call to <tt><nobr>bind2nd</nobr></tt> creates a <p>The call to <tt>bind2nd</tt> creates a <tt>binder2nd</tt> which the
<tt><nobr>binder2nd</nobr></tt> which the Standard defines as follows: Standard defines as follows:</p>
<blockquote><pre> <blockquote>
<pre>
template &lt;class Operation&gt; template &lt;class Operation&gt;
class binder2nd class binder2nd
: public unary_function&lt;typename Operation::first_argument_type, : public unary_function&lt;typename Operation::first_argument_type,
typename Operation::result_type&gt; { typename Operation::result_type&gt; {
... ...
public: public:
binder2nd(const Operation& x, binder2nd(const Operation&amp; x,
<strong>const typename Operation::second_argument_type& y</strong>); <strong>const typename Operation::second_argument_type&amp; y</strong>);
... ...
</pre></blockquote> </pre>
</blockquote>
<p>Since our operation's <tt><nobr>second_argument_type</nobr></tt> is <p>Since our operation's <tt>second_argument_type</tt> is
<tt><nobr>std::ostream&</nobr></tt>, the type of <tt>y</tt> in the <tt>std::ostream&amp;</tt>, the type of <tt>y</tt> in the constructor would
constructor would be <tt><nobr>std::ostream&&</nobr></tt>. Since you be <tt>std::ostream&amp;&amp;</tt>. Since you cannot have a reference to a
cannot have a reference to a reference, at this point we should get a reference, at this point we should get a compilation error because
compilation error because references to references are illegal in C++ references to references are illegal in C++ (but see <a href=
(but see <a "http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html#106">C++
href="http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html#106"> Standard core language active issues list</a>).</p>
C++ Standard core language active issues list</a>).</p>
<p>The binders in this library avoid this problem by using the Boost <p>The binders in this library avoid this problem by using the Boost
<nobr><tt><a <tt><a href="../utility/call_traits.htm">call_traits</a></tt>
href="../utility/call_traits.htm">call_traits</a></tt></nobr> templates.</p> templates.</p>
<p>Our constructor is declared <p>Our constructor is declared</p>
<blockquote><pre> <blockquote>
binder2nd(const Operation& x, <pre>
binder2nd(const Operation&amp; x,
<strong>typename call_traits&lt; <strong>typename call_traits&lt;
typename binary_traits&lt;Operation&gt;::second_argument_type typename binary_traits&lt;Operation&gt;::second_argument_type
&gt;::param_type y</strong>) &gt;::param_type y</strong>)
</pre></blockquote> </pre>
</blockquote>
<p>As a result, <tt>y</tt> has a type of <tt><nobr>std::ostream&</nobr></tt>, <p>As a result, <tt>y</tt> has a type of <tt>std::ostream&amp;</tt>, and
and our example compiles.</p> our example compiles.</p>
<hr>
<hr> <p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
<p>Copyright &copy; 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> "http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional"
height="31" width="88"></a></p>
<p>Revised 28 June 2000</p> <p>Revised
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->02
December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38510" --></p>
<p><i>Copyright &copy; 2000 Cadenza New Zealand Ltd.</i></p>
<p><i>Distributed under the Boost Software License, Version 1.0. (See
accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
copy at <a href=
"http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p>
</body> </body>
</html> </html>

View File

@ -1,25 +1,102 @@
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
// Copyright (c) 2000 Cadenza New Zealand Ltd
// Distributed under the Boost Software License, Version 1.0. (See accompany-
// ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// ------------------------------------------------------------------------------
// Tests for the Boost functional.hpp header file // Tests for the Boost functional.hpp header file
// //
// Note that functional.hpp relies on partial specialisation to be // Note that functional.hpp relies on partial specialisation to be
// effective. If your compiler lacks this feature, very few of the // effective. If your compiler lacks this feature, very few of the
// tests would compile, and so have been excluded from the test. // tests would compile, and so have been excluded from the test.
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
// Copyright (c) 2000
// Cadenza New Zealand Ltd
//
// Permission to use, copy, modify, distribute and sell this software
// and its documentation for any purpose is hereby granted without
// fee, provided that the above copyright notice appears in all copies
// and that both the copyright notice and this permission notice
// appear in supporting documentation. Cadenza New Zealand Ltd makes
// no representations about the suitability of this software for any
// purpose. It is provided "as is" without express or implied
// warranty.
// ------------------------------------------------------------------------------
// $Id$ // $Id$
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
// $Log$ // $Log$
// Revision 1.2.24.1 2006/12/02 14:17:26 andreas_huber69
// Merged L & C issue fixes from trunk to branch.
//
// Revision 1.3 2006/12/02 13:57:32 andreas_huber69
// Fixed license & copyright issues.
//
// From Mark Rodgers Fri Dec 1 12:59:14 2006
// X-Apparently-To: ahd6974-boostorg -at- yahoo.com via 68.142.206.160; Fri, 01 Dec 2006 12:59:41 -0800
// X-Originating-IP: [195.112.4.54]
// Return-Path: <mark.rodgers -at- cadenza.co.nz>
// Authentication-Results: mta550.mail.mud.yahoo.com from=cadenza.co.nz; domainkeys=neutral (no sig)
// Received: from 195.112.4.54 (EHLO smtp.nildram.co.uk) (195.112.4.54) by mta550.mail.mud.yahoo.com with SMTP; Fri, 01 Dec 2006 12:59:40 -0800
// Received: from snagglepuss.cadenza.co.nz (81-6-246-87.dyn.gotadsl.co.uk [81.6.246.87]) by smtp.nildram.co.uk (Postfix) with ESMTP id D32EA2B6D8C for <ahd6974-boostorg -at- yahoo.com>; Fri, 1 Dec 2006 20:59:35 +0000 (GMT)
// Received: from penfold.cadenza.co.nz ([192.168.55.56]) by snagglepuss.cadenza.co.nz with esmtp (Exim 4.63) (envelope-from <mark.rodgers -at- cadenza.co.nz>) id J9M4Y9-0009TO-9K for ahd6974-boostorg -at- yahoo.com; Fri, 01 Dec 2006 20:58:57 +0000
// Message-ID: <457097A2.1090305@cadenza.co.nz>
// Date: Fri, 01 Dec 2006 20:59:14 +0000
// From: "Mark Rodgers" <mark.rodgers -at- cadenza.co.nz>
// User-Agent: Thunderbird 1.5.0.8 (Macintosh/20061025)
// MIME-Version: 1.0
// To: ahd6974-boostorg -at- yahoo.com [Edit - Delete]
// Subject: Re: [boost] Reminder: Need your permission to correct license & copyright issues
// References: <379990.36007.qm@web33507.mail.mud.yahoo.com>
// In-Reply-To: <379990.36007.qm@web33507.mail.mud.yahoo.com>
// Content-Type: text/plain; charset=ISO-8859-1; format=flowed
// Content-Transfer-Encoding: 7bit
// Content-Length: 812
// Gidday Andreas
//
// Sure that's fine. I'm happy for you to do 1, 2 and 3.
//
// Regards
// Mark
//
// Andreas Huber wrote:
// > Hello Mark
// >
// > Quite a while ago it was decided that every file that goes into the
// > 1.34 release of the Boost distribution (www.boost.org) needs uniform
// > license and copyright information. For more information please see:
// >
// > <http://www.boost.org/more/license_info.html>
// >
// > You are receiving this email because several files you contributed
// > lack such information or have an old license:
// >
// > boost/functional/functional.hpp
// > boost/libs/functional/binders.html
// > boost/libs/functional/function_test.cpp
// > boost/libs/functional/function_traits.html
// > boost/libs/functional/index.html
// > boost/libs/functional/mem_fun.html
// > boost/libs/functional/negators.html
// > boost/libs/functional/ptr_fun.html
// > boost/people/mark_rodgers.htm
// >
// > I therefore kindly ask you to grant the permission to do the
// > following:
// >
// > 1. For the files above that already have a license text (all except
// > mark_rodgers.htm), replace the license text with:
// >
// > "Distributed under the Boost Software License, Version 1.0. (See
// > accompanying file LICENSE_1_0.txt or copy at
// > http://www.boost.org/LICENSE_1_0.txt)"
// >
// > 2. For the file that does not yet have a license and copyright
// > (mark_rodgers.htm) add the same license text as under 1. and add the
// > following copyright:
// >
// > "(c) Copyright Mark Rodgers 2000"
// >
// > 3. (Optional) I would also want to convert all HTML files to conform
// > the HTML 4.01 Standard by running them through HTML Tidy, see
// > <http://tidy.sf.net>
// >
// > It would be great if you could grant me permission to do 1 & 2 and
// > optionally also 3.
// >
// > Thank you!
// >
// > Regards,
// >
// > Andreas Huber
// >
//
// Revision 1.2 2001/09/22 11:52:24 johnmaddock // Revision 1.2 2001/09/22 11:52:24 johnmaddock
// Intel C++ fixes: no void return types supported. // Intel C++ fixes: no void return types supported.
// //

View File

@ -1,137 +1,166 @@
<html> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Language" content="en-us">
<title>Boost Function Object Adapter Library</title> <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<title>Boost Function Object Adapter Library</title>
</head> </head>
<body bgcolor="#FFFFFF" text="#000000"> <body bgcolor="#FFFFFF" text="#000000">
<table border="1" bgcolor="#007F7F" cellpadding="2" summary="">
<tr>
<td bgcolor="#FFFFFF"><img src="../../boost.png" alt=
"boost.png (6897 bytes)" width="277" height="86"></td>
<table border="1" bgcolor="#007F7F" cellpadding="2"> <td><a href="../../index.htm"><font face="Arial" color=
<tr> "#FFFFFF"><big>Home</big></font></a></td>
<td bgcolor="#FFFFFF"><img src="../../boost.png" alt="boost.png (6897 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/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>Function Object Traits</h1> <td><a href="../libraries.htm"><font face="Arial" color=
"#FFFFFF"><big>Libraries</big></font></a></td>
<p>The header <nobr><a <td><a href="../../people/people.htm"><font face="Arial" color=
href="../../boost/functional.hpp">functional.hpp</a></nobr> provides two "#FFFFFF"><big>People</big></font></a></td>
traits class templates for functions and function objects:</p>
<table border="1"> <td><a href="../../more/faq.htm"><font face="Arial" color=
<tr> "#FFFFFF"><big>FAQ</big></font></a></td>
<th>Type</th>
<th>Contents</th>
<th>Description</th>
</tr>
<tr>
<td valign="top" rowspan="4"><tt><nobr>template &lt;typename T&gt;</nobr><br><nobr>struct unary_traits<nobr></tt>
</td>
<td valign="top"><tt><nobr>function_type</nobr></tt>
</td>
<td valign="top">The type of the function or function object itself (i.e., <tt>T</tt>).
</td>
</tr>
<tr>
<td valign="top"><tt><nobr>param_type</nobr></tt>
</td>
<td valign="top">The type that should be used to pass the function or function object as a parameter.
</td>
</tr>
<tr>
<td valign="top"><tt><nobr>result_type</nobr></tt>
</td>
<td valign="top">The type returned by the function or function object.
</td>
</tr>
<tr>
<td valign="top"><tt><nobr>argument_type</nobr></tt>
</td>
<td valign="top">The type of the argument to the function or function object.
</td>
</tr>
<tr>
<td valign="top" rowspan="5"><tt><nobr>template &lt;typename T&gt;</nobr><br><nobr>struct binary_traits<nobr></tt>
</td>
<td valign="top"><tt><nobr>function_type</nobr></tt>
</td>
<td valign="top">The type of the function or function object itself (i.e., <tt>T</tt>).
</td>
</tr>
<tr>
<td valign="top"><tt><nobr>param_type</nobr></tt>
</td>
<td valign="top">The type that should be used to pass the function or function object as a parameter.
</td>
</tr>
<tr>
<td valign="top"><tt><nobr>result_type</nobr></tt>
</td>
<td valign="top">The type returned by the function or function object.
</td>
</tr>
<tr>
<td valign="top"><tt><nobr>first_argument_type</nobr></tt>
</td>
<td valign="top">The type of the first argument to the function or function object.
</td>
</tr>
<tr>
<td valign="top"><tt><nobr>second_argument_type</nobr></tt>
</td>
<td valign="top">The type of the second argument to the function or function object.
</td>
</tr>
</table>
<h3>Usage</h3> <td><a href="../../more/index.htm"><font face="Arial" color=
"#FFFFFF"><big>More</big></font></a></td>
</tr>
</table>
<p><tt><nobr>unary_traits</nobr></tt> should be instantiated with <h1>Function Object Traits</h1>
either a function taking a single parameter, or an adaptable unary
function object (i.e., a class derived from
<tt><nobr>std::unary_function</nobr></tt> or one which provides the
same typedefs). (See &sect;20.3.1 in the C++ Standard.)
<p><tt><nobr>binary_traits</nobr></tt> should be instantiated with <p>The header <a href="../../boost/functional.hpp">functional.hpp</a>
either a function taking two parameters, or an adaptable binary provides two traits class templates for functions and function objects:</p>
function object (i.e., a class derived from
<tt><nobr>std::binary_function</nobr></tt> or one which provides the
same typedefs). (See &sect;20.3.1 in the C++ Standard.)
<p>The most common usage of these templates is in function object <table border="1" summary="">
adapters, thus allowing them to adapt plain functions as well as <tr>
function objects. You can do this by wherever you would normally <th>Type</th>
write, for example,
<blockquote><pre> <th>Contents</th>
<th>Description</th>
</tr>
<tr>
<td valign="top" rowspan="4">
<tt>template&nbsp;&lt;typename&nbsp;T&gt;<br>
struct&nbsp;unary_traits</tt></td>
<td valign="top"><tt>function_type</tt></td>
<td valign="top">The type of the function or function object itself
(i.e., <tt>T</tt>).</td>
</tr>
<tr>
<td valign="top"><tt>param_type</tt></td>
<td valign="top">The type that should be used to pass the function or
function object as a parameter.</td>
</tr>
<tr>
<td valign="top"><tt>result_type</tt></td>
<td valign="top">The type returned by the function or function
object.</td>
</tr>
<tr>
<td valign="top"><tt>argument_type</tt></td>
<td valign="top">The type of the argument to the function or function
object.</td>
</tr>
<tr>
<td valign="top" rowspan="5">
<tt>template&nbsp;&lt;typename&nbsp;T&gt;<br>
struct&nbsp;binary_traits</tt></td>
<td valign="top"><tt>function_type</tt></td>
<td valign="top">The type of the function or function object itself
(i.e., <tt>T</tt>).</td>
</tr>
<tr>
<td valign="top"><tt>param_type</tt></td>
<td valign="top">The type that should be used to pass the function or
function object as a parameter.</td>
</tr>
<tr>
<td valign="top"><tt>result_type</tt></td>
<td valign="top">The type returned by the function or function
object.</td>
</tr>
<tr>
<td valign="top"><tt>first_argument_type</tt></td>
<td valign="top">The type of the first argument to the function or
function object.</td>
</tr>
<tr>
<td valign="top"><tt>second_argument_type</tt></td>
<td valign="top">The type of the second argument to the function or
function object.</td>
</tr>
</table>
<h3>Usage</h3>
<p><tt>unary_traits</tt> should be instantiated with either a function
taking a single parameter, or an adaptable unary function object (i.e., a
class derived from <tt>std::unary_function</tt> or one which provides the
same typedefs). (See &sect;20.3.1 in the C++ Standard.)</p>
<p><tt>binary_traits</tt> should be instantiated with either a function
taking two parameters, or an adaptable binary function object (i.e., a
class derived from <tt>std::binary_function</tt> or one which provides the
same typedefs). (See &sect;20.3.1 in the C++ Standard.)</p>
<p>The most common usage of these templates is in function object adapters,
thus allowing them to adapt plain functions as well as function objects.
You can do this by wherever you would normally write, for example,</p>
<blockquote>
<pre>
typename Operation::argument_type typename Operation::argument_type
</pre></blockquote> </pre>
</blockquote>
<p>simply writing <p>simply writing</p>
<blockquote><pre> <blockquote>
<pre>
typename boost::unary_traits&lt;Operation&gt;::argument_type typename boost::unary_traits&lt;Operation&gt;::argument_type
</pre></blockquote> </pre>
</blockquote>
<p>instead. <p>instead.</p>
<h3>Additional Types Defined</h3> <h3>Additional Types Defined</h3>
<p>In addition to the standard result and argument typedefs, these <p>In addition to the standard result and argument typedefs, these traits
traits templates define two additional types. templates define two additional types.</p>
<h4><tt>function_type</tt></h4> <h4><tt>function_type</tt></h4>
<p>This is the type of the function or function object, and can be <p>This is the type of the function or function object, and can be used in
used in declarations such as</p> declarations such as</p>
<blockquote><pre> <blockquote>
<pre>
template &lt;class Predicate&gt; template &lt;class Predicate&gt;
class unary_negate : // ... class unary_negate : // ...
{ {
@ -139,19 +168,21 @@ class unary_negate : // ...
private: private:
<strong>typename unary_traits&lt;Predicate&gt;::function_type</strong> pred; <strong>typename unary_traits&lt;Predicate&gt;::function_type</strong> pred;
}; };
</pre></blockquote> </pre>
</blockquote>
<p>If this typedef were not provided, it would not be possible to <p>If this typedef were not provided, it would not be possible to declare
declare <tt>pred</tt> in a way that would allow <tt>pred</tt> in a way that would allow <tt>unary_negate</tt> to be
<tt><nobr>unary_negate</nobr></tt> to be instantiated with a function instantiated with a function type (see the C++ Standard &sect;14.3.1
type (see the C++ Standard &sect;14.3.1 &para;3). &para;3).</p>
<h4><tt>param_type</tt></h4> <h4><tt>param_type</tt></h4>
<p>This is a type suitable for passing the function or function object <p>This is a type suitable for passing the function or function object as a
as a parameter to another function. For example, parameter to another function. For example,</p>
<blockquote><pre> <blockquote>
<pre>
template &lt;class Predicate&gt; template &lt;class Predicate&gt;
class unary_negate : // ... class unary_negate : // ...
{ {
@ -162,35 +193,41 @@ class unary_negate : // ...
{} {}
// ... // ...
}; };
</pre></blockquote> </pre>
</blockquote>
<p>Function objects are passed by reference to const; function <p>Function objects are passed by reference to const; function pointers are
pointers are passed by value.</p> passed by value.</p>
<h3>Limitations</h3>
<h3>Limitations</h3> <p>This library uses these traits within all function object adapters,
theoretically rendering <tt>ptr_fun</tt> obsolete. However, third party
adapters probably won't take advantage of this mechanism, and so
<tt>ptr_fun</tt> may still be required. Accordingly, this library also
provides <a href="ptr_fun.html">improved versions of the standard function
pointer adapters</a>.</p>
<p>This library uses these traits within all function object adapters, <p>These traits templates will also not work with compilers that fail to
theoretically rendering <tt><nobr>ptr_fun</nobr></tt> obsolete. support partial specialisation of templates. With these compilers, the
However, third party adapters probably won't take advantage of this traits templates can only be instantiated with adaptable function objects,
mechanism, and so <tt><nobr>ptr_fun</nobr></tt> may still be required. thus requiring <tt>ptr_fun</tt> to be used, even with the function object
Accordingly, this library also provides <a adapters in this library.</p>
href="ptr_fun.html">improved versions of the standard function pointer <hr>
adapters</a>.</p>
<p>These traits templates will also not work with compilers that fail <p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
to support partial specialisation of templates. With these compilers, "http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional"
the traits templates can only be instantiated with adaptable function height="31" width="88"></a></p>
objects, thus requiring <tt><nobr>ptr_fun</nobr></tt> to be used, even
with the function object adapters in this library.
<hr> <p>Revised
<p>Copyright &copy; 2000 Cadenza New Zealand Ltd. Permission to copy, <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->02
use, modify, sell and distribute this document is granted provided December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38510" --></p>
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> <p><i>Copyright &copy; 2000 Cadenza New Zealand Ltd.</i></p>
<p><i>Distributed under the Boost Software License, Version 1.0. (See
accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
copy at <a href=
"http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p>
</body> </body>
</html> </html>

View File

@ -1,19 +1,11 @@
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
// Copyright (c) 2000 Cadenza New Zealand Ltd
// Distributed under the Boost Software License, Version 1.0. (See accompany-
// ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
// ------------------------------------------------------------------------------
// Boost functional.hpp header file // Boost functional.hpp header file
// See http://www.boost.org/libs/functional for documentation. // See http://www.boost.org/libs/functional for documentation.
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------
// Copyright (c) 2000
// Cadenza New Zealand Ltd
//
// Permission to use, copy, modify, distribute and sell this software
// and its documentation for any purpose is hereby granted without
// fee, provided that the above copyright notice appears in all copies
// and that both the copyright notice and this permission notice
// appear in supporting documentation. Cadenza New Zealand Ltd makes
// no representations about the suitability of this software for any
// purpose. It is provided "as is" without express or implied
// warranty.
// ------------------------------------------------------------------------------
// $Id$ // $Id$
// ------------------------------------------------------------------------------ // ------------------------------------------------------------------------------

View File

@ -1,97 +1,140 @@
<html> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0"> <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="ProgId" content="FrontPage.Editor.Document"> <meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<title>Boost Function Object Adapter Library</title> <meta name="ProgId" content="FrontPage.Editor.Document">
<title>Boost Function Object Adapter Library</title>
</head> </head>
<body bgcolor="#FFFFFF" text="#000000"> <body bgcolor="#FFFFFF" text="#000000">
<table border="1" bgcolor="#007F7F" cellpadding="2" summary="">
<tr>
<td bgcolor="#FFFFFF"><img src="../../boost.png" alt=
"boost.png (6897 bytes)" width="277" height="86"></td>
<table border="1" bgcolor="#007F7F" cellpadding="2"> <td><a href="../../index.htm"><font face="Arial" color=
<tr> "#FFFFFF"><big>Home</big></font></a></td>
<td bgcolor="#FFFFFF"><img src="../../boost.png" alt="boost.png (6897 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=
<td><a href="../libraries.htm"><font face="Arial" color="#FFFFFF"><big>Libraries</big></font></a></td> "#FFFFFF"><big>Libraries</big></font></a></td>
<td><a href="../../people/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="../../people/people.htm"><font face="Arial" color=
<td><a href="../../more/index.htm"><font face="Arial" color="#FFFFFF"><big>More</big></font></a></td> "#FFFFFF"><big>People</big></font></a></td>
</tr>
</table> <td><a href="../../more/faq.htm"><font face="Arial" color=
<h1>Improved Function Object Adapters</h1> "#FFFFFF"><big>FAQ</big></font></a></td>
<p>The header <nobr><a href="../../boost/functional.hpp">functional.hpp</a></nobr>
provides enhancements to the function object adapters specified in the C++ <td><a href="../../more/index.htm"><font face="Arial" color=
Standard Library (sections 20.3.5, through to 20.3.8). The enhancements are "#FFFFFF"><big>More</big></font></a></td>
principally possible due to two changes:</p> </tr>
<ol> </table>
<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 <h1>Improved Function Object Adapters</h1>
to references</a>, and to improve the efficiency of <a href="mem_fun.html#args">parameter
<p>The header <a href="../../boost/functional.hpp">functional.hpp</a>
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 <tt><a href=
"../utility/call_traits.htm">call_traits</a></tt> 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> 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> <li>We use two <a href="function_traits.html">function object traits</a>
with the adapters in this library.</li> class templates to avoid the need for <tt><a href=
</ol> "ptr_fun.html">ptr_fun</a></tt> with the adapters in this library.</li>
<h3>Contents</h3> </ol>
<p>The header contains the following function and class templates:</p>
<table border="1" cellpadding="5"> <h3>Contents</h3>
<tr>
<th align="left"><a href="function_traits.html">Function object traits</a> <p>The header contains the following function and class templates:</p>
<td valign="top"><tt><nobr>unary_traits</nobr><br>
<nobr>binary_traits</nobr></tt></td> <table border="1" cellpadding="5" summary="">
<td valign="top">Used to determine the types of function objects' and <tr>
functions' arguments. Eliminate the necessity for <nobr><tt>ptr_fun</tt></nobr>.</td> <th align="left"><a href="function_traits.html">Function object
</tr> traits</a></th>
<tr>
<th align="left"><a href="negators.html">Negators</a></th> <td valign="top"><tt>unary_traits<br>
<td valign="top"><tt><nobr>unary_negate</nobr><br> binary_traits</tt></td>
<nobr>binary_negate</nobr><br>
<nobr>not1</nobr><br> <td valign="top">Used to determine the types of function objects' and
<nobr>not2</nobr></tt></td> functions' arguments. Eliminate the necessity for
<td valign="top">Based on section 20.3.5 of the standard.</td> <tt>ptr_fun</tt>.</td>
</tr> </tr>
<tr>
<th align="left"><a href="binders.html">Binders</a></th> <tr>
<td valign="top"><tt><nobr>binder1st</nobr><br> <th align="left"><a href="negators.html">Negators</a></th>
<nobr>binder2nd</nobr><br>
<nobr>bind1st</nobr><br> <td valign="top"><tt>unary_negate<br>
<nobr>bind2nd</nobr></tt></td> binary_negate<br>
<td valign="top">Based on section 20.3.6 of the standard.</td> not1<br>
</tr> not2</tt></td>
<tr>
<th align="left"><a href="ptr_fun.html">Adapters for pointers to functions</a></th> <td valign="top">Based on section 20.3.5 of the standard.</td>
<td valign="top"><tt><nobr>pointer_to_unary_function</nobr><br> </tr>
<nobr>pointer_to_binary_function</nobr><br>
<nobr>ptr_fun</nobr></tt></td> <tr>
<td valign="top">Based on section 20.3.7 of the standard. Not required for <th align="left"><a href="binders.html">Binders</a></th>
use with this library since the binders and negators can adapt functions,
but may be needed with third party adapters.</td> <td valign="top"><tt>binder1st<br>
</tr> binder2nd<br>
<tr> bind1st<br>
<th align="left"><a href="mem_fun.html">Adapters for pointers to member bind2nd</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> functions</a></th>
<td valign="top"><tt><nobr>mem_fun_t</nobr><br>
<nobr>mem_fun1_t</nobr><br> <td valign="top"><tt>pointer_to_unary_function<br>
<nobr>const_mem_fun_t</nobr><br> pointer_to_binary_function<br>
<nobr>const_mem_fun1_t</nobr><br> ptr_fun</tt></td>
<nobr>mem_fun_ref_t</nobr><br>
<nobr>mem_fun1_ref_t</nobr><br> <td valign="top">Based on section 20.3.7 of the standard. Not required
<nobr>const_mem_fun_ref_t</nobr><br> for use with this library since the binders and negators can adapt
<nobr>const_mem_fun1_ref_t</nobr><br> functions, but may be needed with third party adapters.</td>
<nobr>mem_fun</nobr><br> </tr>
<nobr>mem_fun_ref</nobr></tt></td>
<td valign="top">Based on section 20.3.8 of the standard.</td> <tr>
</tr> <th align="left"><a href="mem_fun.html">Adapters for pointers to member
</table> functions</a></th>
<h3>Usage</h3>
<p>Using these adapters should be pretty much the same as using the standard <td valign="top"><tt>mem_fun_t<br>
function object adapters; the only differences are that you need to write <nobr><tt>boost::</tt></nobr> mem_fun1_t<br>
instead of <nobr><tt>std::</tt></nobr>, and that you will get fewer headaches.</p> const_mem_fun_t<br>
<p>For example, suppose you had a <tt>Person</tt> class that contained a <nobr><tt>set_name</tt></nobr> const_mem_fun1_t<br>
function: mem_fun_ref_t<br>
<blockquote> mem_fun1_ref_t<br>
<pre> const_mem_fun_ref_t<br>
const_mem_fun1_ref_t<br>
mem_fun<br>
mem_fun_ref</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 <tt>boost::</tt> instead of <tt>std::</tt>, and that you will get
fewer headaches.</p>
<p>For example, suppose you had a <tt>Person</tt> class that contained a
<tt>set_name</tt> function:</p>
<blockquote>
<pre>
class Person class Person
{ {
public: public:
@ -99,86 +142,122 @@ class Person
// ... // ...
}; };
</pre> </pre>
</blockquote> </blockquote>
<p>You could rename a bunch of people in a collection, <tt>c</tt>, by writing</p>
<blockquote> <p>You could rename a bunch of people in a collection, <tt>c</tt>, by
<pre> writing</p>
<blockquote>
<pre>
std::for_each(c.begin(), c.end(), std::for_each(c.begin(), c.end(),
boost::bind2nd(boost::mem_fun_ref(&amp;Person::set_name), &quot;Fred&quot;)); boost::bind2nd(boost::mem_fun_ref(&amp;Person::set_name), "Fred"));
</pre> </pre>
</blockquote> </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 <p>If the standard adapters had been used instead then this code would
argument. Refer to the comments in the <a href="binders.html#refref">binder normally fail to compile, because <tt>set_name</tt> takes a reference
documentation</a> to explain why this is so.</p> argument. Refer to the comments in the <a href="binders.html#refref">binder
<h3>Compiler Compatibility</h3> documentation</a> to explain why this is so.</p>
<p>The header and <a href="function_test.cpp">test program</a> have been
compiled with the following compilers:</p> <h3>Compiler Compatibility</h3>
<table border="1" cellpadding="5">
<tr> <p>The header and <a href="function_test.cpp">test program</a> have been
<th>Compiler</th> compiled with the following compilers:</p>
<th>Comments</th>
</tr> <table border="1" cellpadding="5" summary="">
<tr> <tr>
<td valign="top">Borland C++Builder 4 Update 2</td> <th>Compiler</th>
<td valign="top">No known issues.</td>
</tr> <th>Comments</th>
<tr> </tr>
<td valign="top">Borland C++ 5.5</td>
<td valign="top">No known issues.</td> <tr>
</tr> <td valign="top">Borland C++Builder 4 Update 2</td>
<tr>
<td valign="top">g++ 2.95.2</td> <td valign="top">No known issues.</td>
<td valign="top">No known issues.</td> </tr>
</tr>
<tr> <tr>
<td valign="top">Microsoft Visual C++ Service Pack 3</td> <td valign="top">Borland C++ 5.5</td>
<td valign="top">Compiler lacks partial specialisation, so this library
offers little more than is provided by the standard adapters: <td valign="top">No known issues.</td>
<ul> </tr>
<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 <tr>
usable in fewer situations.</li> <td valign="top">g++ 2.95.2</td>
<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> <td valign="top">No known issues.</td>
continues to be required to adapt functions. </tr>
</ul>
</td> <tr>
</tr> <td valign="top">Microsoft Visual C++ Service Pack 3</td>
</table>
<h3>Future Directions</h3> <td valign="top">
<p>This library's primary focus is to solve the problem of references to Compiler lacks partial specialisation, so this library offers little
references while maintaining as much compatibility as possible with the standard more than is provided by the standard adapters:
library. This allows you to use the techniques you read about in books and
magazines with many of today's compilers.</p> <ul>
<p>In the longer term, even better solutions are likely:</p> <li>The <tt>call_traits</tt> mechanism is unable to prevent
<ol> references to references, and so the adapters in this library will
<li>Several Boost members are working on expression template libraries. These be usable in fewer situations.</li>
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 <li>The <tt>function_traits</tt> mechanism is unable to determine
widely supported by major compilers but shows great promise. In the the argument and result types of functions, therefore
meantime, the functional.hpp library fills the gap.</li> <tt>ptr_fun</tt> continues to be required to adapt functions.</li>
<li>The Standard Committee has recognised the problem of references to </ul>
references occurring during template instantiation and has moved to fix the </td>
standard (see the <a href="http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html#106">C++ </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> standard core language active issues list</a>).</li>
</ol> </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 <20> 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 &quot;as is&quot; without
express or implied warranty, and with no claim as to its suitability for any
purpose.</p>
<p>Revised 28 June 2000</p>
<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>.</p>
<hr>
<p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
"http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional"
height="31" width="88"></a></p>
<p>Revised
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->02
December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38510" --></p>
<p><i>Copyright &copy; 2000 Cadenza New Zealand Ltd.</i></p>
<p><i>Distributed under the Boost Software License, Version 1.0. (See
accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
copy at <a href=
"http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p>
</body> </body>
</html> </html>

View File

@ -1,171 +1,201 @@
<html> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Language" content="en-us">
<title>Boost Function Object Adapter Library</title> <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<title>Boost Function Object Adapter Library</title>
</head> </head>
<body bgcolor="#FFFFFF" text="#000000"> <body bgcolor="#FFFFFF" text="#000000">
<table border="1" bgcolor="#007F7F" cellpadding="2" summary="">
<tr>
<td bgcolor="#FFFFFF"><img src="../../boost.png" alt=
"boost.png (6897 bytes)" width="277" height="86"></td>
<table border="1" bgcolor="#007F7F" cellpadding="2"> <td><a href="../../index.htm"><font face="Arial" color=
<tr> "#FFFFFF"><big>Home</big></font></a></td>
<td bgcolor="#FFFFFF"><img src="../../boost.png" alt="boost.png (6897 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/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>Member Function Adapters</h1> <td><a href="../libraries.htm"><font face="Arial" color=
"#FFFFFF"><big>Libraries</big></font></a></td>
<p>The header <nobr><a <td><a href="../../people/people.htm"><font face="Arial" color=
href="../../boost/functional.hpp">functional.hpp</a></nobr> includes "#FFFFFF"><big>People</big></font></a></td>
improved versions of the full range of member function adapters from
the the C++ Standard Library <nobr>(&sect 20.3.8):</nobr></p>
<ul> <td><a href="../../more/faq.htm"><font face="Arial" color=
<li><tt>mem_fun_t</tt></li> "#FFFFFF"><big>FAQ</big></font></a></td>
<li><tt>mem_fun1_t</tt></li>
<li><tt>const_mem_fun_t</tt></li>
<li><tt>const_mem_fun1_t</tt></li>
<li><tt>mem_fun_ref_t</tt></li>
<li><tt>mem_fun1_ref_t</tt></li>
<li><tt>const_mem_fun_ref_t</tt></li>
<li><tt>const_mem_fun1_ref_t</tt></li>
</ul>
<p>as well as the corresponding overloaded helper functions<p> <td><a href="../../more/index.htm"><font face="Arial" color=
<ul> "#FFFFFF"><big>More</big></font></a></td>
<li><tt>mem_fun</tt></li> </tr>
<li><tt>mem_fun_ref</tt></li> </table>
</ul>
<p>The following changes have been made to the adapters as specified <h1>Member Function Adapters</h1>
in the Standard:</p>
<ul> <p>The header <a href="../../boost/functional.hpp">functional.hpp</a>
<li>The <tt><nobr>first_argument_type</nobr></tt> typedef has been includes improved versions of the full range of member function adapters
corrected for the <nobr><tt>const_</tt></nobr> family of member from the the C++ Standard Library (&sect;20.3.8):</p>
function adapters (see <a href="#firstarg">below</a>).</li>
<li>The argument passed to <tt><nobr>mem_fun1_t</nobr></tt> and its <ul>
variants is passed using the <li><tt>mem_fun_t</tt></li>
<tt><nobr>call_traits::param_type</nobr></tt> for the member
function's argument type.
</ul>
<h3 id="firstarg">first_argument_type</h3> <li><tt>mem_fun1_t</tt></li>
<p>The standard specifies <tt><nobr>const_mem_fun1_t</nobr></tt>, for example, like this: <li><tt>const_mem_fun_t</tt></li>
<blockquote><pre> <li><tt>const_mem_fun1_t</tt></li>
<li><tt>mem_fun_ref_t</tt></li>
<li><tt>mem_fun1_ref_t</tt></li>
<li><tt>const_mem_fun_ref_t</tt></li>
<li><tt>const_mem_fun1_ref_t</tt></li>
</ul>
<p>as well as the corresponding overloaded helper functions</p>
<ul>
<li><tt>mem_fun</tt></li>
<li><tt>mem_fun_ref</tt></li>
</ul>
<p>The following changes have been made to the adapters as specified in the
Standard:</p>
<ul>
<li>The <tt>first_argument_type</tt> typedef has been corrected for the
<tt>const_</tt> family of member function adapters (see <a href=
"#firstarg">below</a>).</li>
<li>The argument passed to <tt>mem_fun1_t</tt> and its variants is passed
using the <tt>call_traits::param_type</tt> for the member function's
argument type.</li>
</ul>
<h3 id="firstarg">first_argument_type</h3>
<p>The standard specifies <tt>const_mem_fun1_t</tt>, for example, like
this:</p>
<blockquote>
<pre>
template &lt;class S, class T, class A&gt; class const_mem_fun1_t template &lt;class S, class T, class A&gt; class const_mem_fun1_t
: public binary_function&lt;<strong>T*</strong>, A, S&gt; { : public binary_function&lt;<strong>T*</strong>, A, S&gt; {
public: public:
explicit const_mem_fun1_t(S (T::*p)(A) const); explicit const_mem_fun1_t(S (T::*p)(A) const);
S operator()(<strong>const T*</strong> p, A x) const; S operator()(<strong>const T*</strong> p, A x) const;
}; };
</pre></blockquote> </pre>
</blockquote>
<p>Note that the first argument to <p>Note that the first argument to <tt>binary_function</tt> is <tt>T*</tt>
<tt><nobr>binary_function</nobr></tt> is <tt><nobr>T*</nobr></tt> despite the fact that the first argument to <tt>operator()</tt> is actually
despite the fact that the first argument to <tt><nobr>operator()</nobr></tt> is of type <tt><em>const</em>&nbsp;T*</tt>.</p>
actually of type <tt><nobr><em>const</em> T*</nobr></tt>.
<p>Does this matter? Well, consider what happens when we write <p>Does this matter? Well, consider what happens when we write</p>
<blockquote><pre> <blockquote>
<pre>
struct Foo { void bar(int) const; }; struct Foo { void bar(int) const; };
const Foo *cp = new Foo; const Foo *cp = new Foo;
std::bind1st(std::mem_fun(&Foo::bar), cp); std::bind1st(std::mem_fun(&amp;Foo::bar), cp);
</pre></blockquote> </pre>
</blockquote>
<p>We have created a <tt><nobr>const_mem_fun1_t</nobr></tt> object <p>We have created a <tt>const_mem_fun1_t</tt> object which will
which will effectively contain the following effectively contain the following</p>
<blockquote><pre> <blockquote>
<pre>
typedef Foo* first_argument_type; typedef Foo* first_argument_type;
</pre></blockquote> </pre>
</blockquote>
<p>The <tt><nobr>bind1st</nobr></tt> will then create a <p>The <tt>bind1st</tt> will then create a <tt>binder1st</tt> object that
<tt><nobr>binder1st</nobr></tt> object that will use this will use this <tt>typedef</tt> as the type of a member which will be
<tt><nobr>typedef</nobr></tt> as the type of a member which will be initialised with <tt>cp</tt>. In other words, we will need to initialise a
initialised with <tt><nobr>cp</nobr></tt>. In other words, we will <tt>Foo*</tt> member with a <tt>const&nbsp;Foo*</tt> pointer! Clearly this
need to initialise a <tt><nobr>Foo*</nobr></tt> member with a is not possible, so to implement this your Standard Library vendor will
<tt><nobr>const Foo*</nobr></tt> pointer! Clearly this is not have had to cast away the constness of <tt>cp</tt>, probably within the
possible, so to implement this your Standard Library vendor will have body of <tt>bind1st</tt>.</p>
had to cast away the constness of <tt><nobr>cp</nobr></tt>, probably
within the body of <tt><nobr>bind1st</nobr></tt>.
<p>This hack will not suffice with the improved <a <p>This hack will not suffice with the improved <a href=
href="binders.html">binders</a> in this library, so we have had to "binders.html">binders</a> in this library, so we have had to provide
provide corrected versions of the member function adapters as well. corrected versions of the member function adapters as well.</p>
<h3 id="args">Argument Types</h3>
<h3 id="args">Argument Types</h3> <p>The standard defines <tt>mem_fun1_t</tt>, for example, like this
(&sect;20.3.8&nbsp;&para;2):</p>
<p>The standard defines <nobr><tt>mem_fun1_t</tt></nobr>, for example, like this <blockquote>
<nobr>(&sect;20.3.8 &para;2):</nobr> <pre>
<blockquote><pre>
template &lt;class S, class T, class A&gt; class mem_fun1_t template &lt;class S, class T, class A&gt; class mem_fun1_t
: public binary_function&lt;T*, A, S&gt; { : public binary_function&lt;T*, A, S&gt; {
public: public:
explicit mem_fun1_t(S (T::*p)(<strong>A</strong>)); explicit mem_fun1_t(S (T::*p)(<strong>A</strong>));
S operator()(T* p, <strong>A</strong> x) const; S operator()(T* p, <strong>A</strong> x) const;
}; };
</pre></blockquote> </pre>
</blockquote>
<p>Note that the second argument to <nobr><tt>operator()</tt></nobr> is <p>Note that the second argument to <tt>operator()</tt> is exactly the same
exactly the same type as the argument to the member function. If this type as the argument to the member function. If this is a value type, the
is a value type, the argument will be passed by value and copied twice. argument will be passed by value and copied twice.</p>
<p>However, if we were to try and eliminate this inefficiency by <p>However, if we were to try and eliminate this inefficiency by instead
instead declaring the argument as <nobr><tt>const A&</tt></nobr>, then declaring the argument as <tt>const&nbsp;A&amp;</tt>, then if A were a
if A were a reference type, we would have a reference to a reference, reference type, we would have a reference to a reference, which is
which is currently illegal (but see <a currently illegal (but see <a href=
href="http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html#106">C++ "http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html#106">C++ core
core language issue number 106)</a> language issue number 106)</a></p>
<p>So the way in which we want to declare the second argument for <p>So the way in which we want to declare the second argument for
<nobr><tt>operator()</tt></nobr> depends on whether or not the member <tt>operator()</tt> depends on whether or not the member function's
function's argument is a reference. If it is a reference, we want to argument is a reference. If it is a reference, we want to declare it simply
declare it simply as <nobr><tt>A</tt></nobr>; if it is a value we want as <tt>A</tt>; if it is a value we want to declare it as
to declare it as <nobr><tt>const A&</tt></nobr>. <tt>const&nbsp;A&amp;</tt>.</p>
<p>The Boost <nobr><a <p>The Boost <a href="../utility/call_traits.htm">call_traits</a> class
href="../utility/call_traits.htm">call_traits</a></nobr> class template contains a <tt>param_type</tt> typedef, which uses partial
template contains a <tt><nobr>param_type</nobr></tt> typedef, which specialisation to make precisely this decision. By declaring the
uses partial specialisation to make precisely this decision. By <tt>operator()</tt> as</p>
declaring the <nobr><tt>operator()</tt></nobr> as
<blockquote><pre> <blockquote>
<pre>
S operator()(T* p, typename call_traits&lt;A&gt;::param_type x) const S operator()(T* p, typename call_traits&lt;A&gt;::param_type x) const
</pre></blockquote> </pre>
</blockquote>
<p>we achieve the desired result - we improve efficiency without <p>we achieve the desired result - we improve efficiency without generating
generating references to references.</p> references to references.</p>
<h3>Limitations</h3> <h3>Limitations</h3>
<p>The call traits template used to realise some improvements relies <p>The call traits template used to realise some improvements relies on
on partial specialisation, so these improvements are only available on partial specialisation, so these improvements are only available on
compilers that support that feature. With other compilers, the compilers that support that feature. With other compilers, the argument
argument passed to the member function (in the passed to the member function (in the <tt>mem_fun1_t</tt> family) will
<nobr><tt>mem_fun1_t</tt></nobr> family) will always be passed by always be passed by reference, thus generating the possibility of
reference, thus generating the possibility of references to references. references to references.</p>
<hr>
<hr> <p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
"http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional"
height="31" width="88"></a></p>
<p>Copyright &copy; 2000 Cadenza New Zealand Ltd. Permission to copy, <p>Revised
use, modify, sell and distribute this document is granted provided <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->02 December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38510" --></p>
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> <p><i>Copyright &copy; 2000 Cadenza New Zealand Ltd.</i></p>
<p><i>Distributed under the Boost Software License, Version 1.0. (See
accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
copy at <a href=
"http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p>
</body> </body>
</html> </html>

View File

@ -1,132 +1,158 @@
<html> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Language" content="en-us">
<title>Boost Function Object Adapter Library</title> <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<title>Boost Function Object Adapter Library</title>
</head> </head>
<body bgcolor="#FFFFFF" text="#000000"> <body bgcolor="#FFFFFF" text="#000000">
<table border="1" bgcolor="#007F7F" cellpadding="2" summary="">
<tr>
<td bgcolor="#FFFFFF"><img src="../../boost.png" alt=
"boost.png (6897 bytes)" width="277" height="86"></td>
<table border="1" bgcolor="#007F7F" cellpadding="2"> <td><a href="../../index.htm"><font face="Arial" color=
<tr> "#FFFFFF"><big>Home</big></font></a></td>
<td bgcolor="#FFFFFF"><img src="../../boost.png" alt="boost.png (6897 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/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>Negators</h1> <td><a href="../libraries.htm"><font face="Arial" color=
"#FFFFFF"><big>Libraries</big></font></a></td>
<p>The header <nobr><a <td><a href="../../people/people.htm"><font face="Arial" color=
href="../../boost/functional.hpp">functional.hpp</a></nobr> provides "#FFFFFF"><big>People</big></font></a></td>
enhanced versions of both the negator adapters from the C++ Standard
Library (&sect;20.3.5):</p>
<ul> <td><a href="../../more/faq.htm"><font face="Arial" color=
<li><tt>unary_negate</tt></li> "#FFFFFF"><big>FAQ</big></font></a></td>
<li><tt>binary_negate</tt></li>
</ul>
<p>As well as the corresponding helper functions</p> <td><a href="../../more/index.htm"><font face="Arial" color=
"#FFFFFF"><big>More</big></font></a></td>
</tr>
</table>
<ul> <h1>Negators</h1>
<li><tt>not1</tt></li>
<li><tt>not2</tt></li>
</ul>
<p>However, the negators in this library improve on the standard <p>The header <a href="../../boost/functional.hpp">functional.hpp</a>
versions in two ways: provides enhanced versions of both the negator adapters from the C++
Standard Library (&sect;20.3.5):</p>
<ul> <ul>
<li>They use <a href="function_traits.html">function object traits</a> <li><tt>unary_negate</tt></li>
to avoid the need for <tt><nobr>ptr_fun</nobr></tt> when negating a
function rather than an adaptable function object.
</li>
<li>They use Boost <nobr><a
href="../utility/call_traits.htm">call traits</a></nobr> to determine
the best way to declare their arguments and pass them through
to the adapted function (see <a href="#arguments">below</a>).
</li>
</ul>
<h3>Usage</h3> <li><tt>binary_negate</tt></li>
</ul>
<p>Usage is identical to the standard negators. For example,</p> <p>As well as the corresponding helper functions</p>
<blockquote><pre> <ul>
bool bad(const Foo &foo) { ... } <li><tt>not1</tt></li>
<li><tt>not2</tt></li>
</ul>
<p>However, the negators in this library improve on the standard versions
in two ways:</p>
<ul>
<li>They use <a href="function_traits.html">function object traits</a> to
avoid the need for <tt>ptr_fun</tt> when negating a function rather than
an adaptable function object.</li>
<li>They use Boost <a href=
"../utility/call_traits.htm">call&nbsp;traits</a> to determine the best
way to declare their arguments and pass them through to the adapted
function (see <a href="#arguments">below</a>).</li>
</ul>
<h3>Usage</h3>
<p>Usage is identical to the standard negators. For example,</p>
<blockquote>
<pre>
bool bad(const Foo &amp;foo) { ... }
... ...
std::vector&lt;Foo&gt; c; std::vector&lt;Foo&gt; c;
... ...
std::find_if(c.begin(), c.end(), boost::not1(bad)); std::find_if(c.begin(), c.end(), boost::not1(bad));
</pre></blockquote> </pre>
</blockquote>
<h3 id="arguments">Argument Types</h3> <h3 id="arguments">Argument Types</h3>
<p>The C++ Standard <nobr>(&sect;20.3.5)</nobr> defines unary negate <p>The C++ Standard (&sect;20.3.5) defines unary negate like this (binary
like this (binary negate is similar):</p> negate is similar):</p>
<blockquote><pre> <blockquote>
<pre>
template &lt;class Predicate&gt; template &lt;class Predicate&gt;
class unary_negate class unary_negate
: public unary_function&lt;typename Predicate::argument_type,bool&gt; { : public unary_function&lt;typename Predicate::argument_type,bool&gt; {
public: public:
explicit unary_negate(const Predicate& pred); explicit unary_negate(const Predicate&amp; pred);
bool operator()(<strong>const typename Predicate::argument_type&</strong> x) const; bool operator()(<strong>const typename Predicate::argument_type&amp;</strong> x) const;
};</pre></blockquote> };
</pre>
</blockquote>
<p>Note that if the Predicate's <nobr><tt>argument_type</tt></nobr> is <p>Note that if the Predicate's <tt>argument_type</tt> is a reference, the
a reference, the type of <nobr><tt>operator()</tt>'s</nobr> argument type of <tt>operator()</tt>'s argument would be a reference to a reference.
would be a reference to a reference. Currently this is illegal in C++ Currently this is illegal in C++ (but see the <a href=
(but see the <a "http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html#106">C++
href="http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html#106"> standard core language active issues list</a>).</p>
C++ standard core language active issues list</a>).</p>
<p>However, if we instead defined <nobr><tt>operator()</tt></nobr> <p>However, if we instead defined <tt>operator()</tt> to accept Predicate's
to accept Predicate's argument_type unmodified, this would be argument_type unmodified, this would be needlessly inefficient if it were a
needlessly inefficient if it were a value type; the argument would be value type; the argument would be copied twice - once when calling
copied twice - once when calling <nobr><tt>unary_negate</tt>'s</nobr> <tt>unary_negate</tt>'s <tt>operator()</tt>, and again when
<nobr><tt>operator()</tt></nobr>, and again when <nobr><tt>operator()</tt></nobr> <tt>operator()</tt> called the adapted function.</p>
called the adapted function.</p>
<p>So how we want to declare the argument for <p>So how we want to declare the argument for <tt>operator()</tt> depends
<nobr><tt>operator()</tt></nobr> depends on whether or not the on whether or not the Predicate's <tt>argument_type</tt> is a reference. If
Predicate's <nobr><tt>argument_type</tt></nobr> is a reference. If it it is a reference, we want to declare it simply as <tt>argument_type</tt>;
is a reference, we want to declare it simply as if it is a value we want to declare it as
<nobr><tt>argument_type</tt></nobr>; if it is a value we want to <tt>const&nbsp;argument_type&amp;</tt>.</p>
declare it as <nobr><tt>const argument_type&</tt></nobr>.
<p>The Boost <nobr><a <p>The Boost <a href="../utility/call_traits.htm">call_traits</a> class
href="../utility/call_traits.htm">call_traits</a></nobr> class template contains a <tt>param_type</tt> typedef, which uses partial
template contains a <tt><nobr>param_type</nobr></tt> typedef, which specialisation to make precisely this decision. If we were to declare
uses partial specialisation to make precisely this decision. If we were <tt>operator()</tt> as</p>
to declare <nobr><tt>operator()</tt></nobr> as</p>
<blockquote><pre> <blockquote>
<pre>
bool operator()(typename call_traits&lt;typename Predicate::argument_type&gt;::param_type x) const bool operator()(typename call_traits&lt;typename Predicate::argument_type&gt;::param_type x) const
</pre></blockquote> </pre>
</blockquote>
<p>the desired result would be achieved - we would eliminate <p>the desired result would be achieved - we would eliminate references to
references to references without loss of efficiency. In fact, the references without loss of efficiency. In fact, the actual declaration is
actual declaration is slightly more complicated because of the use of slightly more complicated because of the use of function object traits, but
function object traits, but the effect remains the same.</p> the effect remains the same.</p>
<h3>Limitations</h3> <h3>Limitations</h3>
<p>Both the function object traits and call traits used to realise <p>Both the function object traits and call traits used to realise these
these improvements rely on partial specialisation, these improvements improvements rely on partial specialisation, these improvements are only
are only available on compilers that support that feature. With other available on compilers that support that feature. With other compilers, the
compilers, the negators in this library behave very much like those negators in this library behave very much like those in the Standard -
in the Standard - <nobr><tt>ptr_fun</tt></nobr> will be required to <tt>ptr_fun</tt> will be required to adapt functions, and references to
adapt functions, and references to references will not be avoided. references will not be avoided.</p>
<hr>
<hr> <p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
<p>Copyright &copy; 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> "http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional"
height="31" width="88"></a></p>
<p>Revised 28 June 2000</p> <p>Revised
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->02
December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38510" --></p>
<p><i>Copyright &copy; 2000 Cadenza New Zealand Ltd.</i></p>
<p><i>Distributed under the Boost Software License, Version 1.0. (See
accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
copy at <a href=
"http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p>
</body> </body>
</html> </html>

View File

@ -1,135 +1,158 @@
<html> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Language" content="en-us">
<title>Boost Function Object Adapter Library</title> <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<title>Boost Function Object Adapter Library</title>
</head> </head>
<body bgcolor="#FFFFFF" text="#000000"> <body bgcolor="#FFFFFF" text="#000000">
<table border="1" bgcolor="#007F7F" cellpadding="2" summary="">
<tr>
<td bgcolor="#FFFFFF"><img src="../../boost.png" alt=
"boost.png (6897 bytes)" width="277" height="86"></td>
<table border="1" bgcolor="#007F7F" cellpadding="2"> <td><a href="../../index.htm"><font face="Arial" color=
<tr> "#FFFFFF"><big>Home</big></font></a></td>
<td bgcolor="#FFFFFF"><img src="../../boost.png" alt="boost.png (6897 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/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>Function Pointer Adapters</h1> <td><a href="../libraries.htm"><font face="Arial" color=
"#FFFFFF"><big>Libraries</big></font></a></td>
<p>The header <nobr><a <td><a href="../../people/people.htm"><font face="Arial" color=
href="../../boost/functional.hpp">functional.hpp</a></nobr> provides "#FFFFFF"><big>People</big></font></a></td>
enhanced versions of both the function pointer adapters from the C++
Standard Library <nobr>(&sect 20.3.7):</nobr></p>
<ul> <td><a href="../../more/faq.htm"><font face="Arial" color=
<li><tt>pointer_to_unary_function</tt></li> "#FFFFFF"><big>FAQ</big></font></a></td>
<li><tt>pointer_to_binary_function</tt></li>
</ul>
<p>As well as the corresponding helper function template:</p> <td><a href="../../more/index.htm"><font face="Arial" color=
"#FFFFFF"><big>More</big></font></a></td>
</tr>
</table>
<ul> <h1>Function Pointer Adapters</h1>
<li><tt>ptr_fun</tt></li>
</ul>
<p>However, you should not need to use the adapters in conjunction <p>The header <a href="../../boost/functional.hpp">functional.hpp</a>
with the adapters in this library due to our use of <a provides enhanced versions of both the function pointer adapters from the
href="function_traits.html">function object traits</a>. You will C++ Standard Library (&sect;20.3.7):</p>
however need to use them if your implementation fails to work properly
with our traits classes (due to lack if partial specialisation), or if
you wish to use a function object adapter from a third party.
<h3>Usage</h3> <ul>
<li><tt>pointer_to_unary_function</tt></li>
<p>If you need to use these adapters, usage is identical to the <li><tt>pointer_to_binary_function</tt></li>
standard function pointer adapters. For example,</p> </ul>
<blockquote><pre> <p>As well as the corresponding helper function template:</p>
<ul>
<li><tt>ptr_fun</tt></li>
</ul>
<p>However, you should not need to use the adapters in conjunction with the
adapters in this library due to our use of <a href=
"function_traits.html">function object traits</a>. You will however need to
use them if your implementation fails to work properly with our traits
classes (due to lack if partial specialisation), or if you wish to use a
function object adapter from a third party.</p>
<h3>Usage</h3>
<p>If you need to use these adapters, usage is identical to the standard
function pointer adapters. For example,</p>
<blockquote>
<pre>
bool bad(std::string foo) { ... } bool bad(std::string foo) { ... }
... ...
std::vector&lt;std::string&gt; c; std::vector&lt;std::string&gt; c;
... ...
std::vector&lt;std::string&gt;::iterator it std::vector&lt;std::string&gt;::iterator it
= std::find_if(c.begin(), c.end(), std::not1(boost::ptr_fun(bad))); = std::find_if(c.begin(), c.end(), std::not1(boost::ptr_fun(bad)));
</pre></blockquote> </pre>
</blockquote>
<p>Note however that this library contains enhanced <a <p>Note however that this library contains enhanced <a href=
href="negators.html">negators</a> that support function object traits, "negators.html">negators</a> that support function object traits, so the
so the line above could equally be written line above could equally be written</p>
<blockquote><pre> <blockquote>
<pre>
std::vector&lt;std::string&gt;::iterator it std::vector&lt;std::string&gt;::iterator it
= std::find_if(c.begin(), c.end(), boost::not1(bad)); = std::find_if(c.begin(), c.end(), boost::not1(bad));
</pre></blockquote> </pre>
</blockquote>
<h3>Argument Types</h3> <h3>Argument Types</h3>
<p>The standard defines <p>The standard defines <tt>pointer_to_unary_function</tt> like this
<nobr><tt>pointer_to_unary_function</tt></nobr> like this (&sect;20.3.8&nbsp;&para;2):</p>
<nobr>(&sect;20.3.8 &para;2):</nobr>
<blockquote><pre> <blockquote>
<pre>
template &lt;class Arg, class Result&gt; template &lt;class Arg, class Result&gt;
class pointer_to_unary_function : public unary_function&lt;Arg, Result&gt; { class pointer_to_unary_function : public unary_function&lt;Arg, Result&gt; {
public: public:
explicit pointer_to_unary_function(Result (* f)(<strong>Arg</strong>)); explicit pointer_to_unary_function(Result (* f)(<strong>Arg</strong>));
Result operator()(<strong>Arg</strong> x) const; Result operator()(<strong>Arg</strong> x) const;
}; };
</pre></blockquote> </pre>
</blockquote>
<p>Note that the argument to <nobr><tt>operator()</tt></nobr> is <p>Note that the argument to <tt>operator()</tt> is exactly the same type
exactly the same type as the argument to the wrapped function. If this as the argument to the wrapped function. If this is a value type, the
is a value type, the argument will be passed by value and copied twice. argument will be passed by value and copied twice.
<nobr><tt>pointer_to_binary_function</tt></nobr> has a similar problem. <tt>pointer_to_binary_function</tt> has a similar problem.</p>
<p>However, if we were to try and eliminate this inefficiency by <p>However, if we were to try and eliminate this inefficiency by instead
instead declaring the argument as <nobr><tt>const Arg&</tt></nobr>, then declaring the argument as <tt>const&nbsp;Arg&amp;</tt>, then if Arg were a
if Arg were a reference type, we would have a reference to a reference, reference type, we would have a reference to a reference, which is
which is currently illegal (but see <a currently illegal (but see <a href=
href="http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html#106">C++ "http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html#106">C++ core
core language issue number 106)</a> language issue number 106)</a></p>
<p>So the way in which we want to declare the argument for <p>So the way in which we want to declare the argument for
<nobr><tt>operator()</tt></nobr> depends on whether or not the <tt>operator()</tt> depends on whether or not the wrapped function's
wrapped function's argument is a reference. If it argument is a reference. If it is a reference, we want to declare it simply
is a reference, we want to declare it simply as as <tt>Arg</tt>; if it is a value we want to declare it as
<nobr><tt>Arg</tt></nobr>; if it is a value we want to <tt>const&nbsp;Arg&amp;</tt>.</p>
declare it as <nobr><tt>const Arg&</tt></nobr>.
<p>The Boost <nobr><a <p>The Boost <a href="../utility/call_traits.htm">call_traits</a> class
href="../utility/call_traits.htm">call_traits</a></nobr> class template contains a <tt>param_type</tt> typedef, which uses partial
template contains a <tt><nobr>param_type</nobr></tt> typedef, which specialisation to make precisely this decision. By declaring the
uses partial specialisation to make precisely this decision. By <tt>operator()</tt> as</p>
declaring the <nobr><tt>operator()</tt></nobr> as
<blockquote><pre> <blockquote>
<pre>
Result operator()(typename call_traits&lt;Arg&gt;::param_type x) const Result operator()(typename call_traits&lt;Arg&gt;::param_type x) const
</pre></blockquote> </pre>
</blockquote>
<p>we achieve the desired result - we improve efficiency without <p>we achieve the desired result - we improve efficiency without generating
generating references to references.</p> references to references.</p>
<h3>Limitations</h3> <h3>Limitations</h3>
<p>The call traits template used to realise this improvement relies <p>The call traits template used to realise this improvement relies on
on partial specialisation, so this improvement is only available on partial specialisation, so this improvement is only available on compilers
compilers that support that feature. With other compilers, the that support that feature. With other compilers, the argument passed to the
argument passed to the function will always be passed by function will always be passed by reference, thus generating the
reference, thus generating the possibility of references to references. possibility of references to references.</p>
<hr>
<hr> <p><a href="http://validator.w3.org/check?uri=referer"><img border="0" src=
"http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01 Transitional"
height="31" width="88"></a></p>
<p>Copyright &copy; 2000 Cadenza New Zealand Ltd. Permission to copy, <p>Revised
use, modify, sell and distribute this document is granted provided <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->02
this copyright notice appears in all copies. This document is provided December, 2006<!--webbot bot="Timestamp" endspan i-checksum="38510" --></p>
"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> <p><i>Copyright &copy; 2000 Cadenza New Zealand Ltd.</i></p>
<p><i>Distributed under the Boost Software License, Version 1.0. (See
accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
copy at <a href=
"http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</a>)</i></p>
</body> </body>
</html> </html>