1 <!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN">
5 <meta http-equiv=
"Content-Language" content=
"en-us">
6 <meta http-equiv=
"Content-Type" content=
"text/html; charset=us-ascii">
8 <title>Boost Function Object Adapter Library
</title>
11 <body bgcolor=
"#FFFFFF" text=
"#000000">
12 <table border=
"1" bgcolor=
"#007F7F" cellpadding=
"2" summary=
"">
14 <td bgcolor=
"#FFFFFF"><img src=
"../../boost.png" alt=
15 "boost.png (6897 bytes)" width=
"277" height=
"86"></td>
17 <td><a href=
"../../index.htm"><font face=
"Arial" color=
18 "#FFFFFF"><big>Home
</big></font></a></td>
20 <td><a href=
"../libraries.htm"><font face=
"Arial" color=
21 "#FFFFFF"><big>Libraries
</big></font></a></td>
23 <td><a href=
"http://www.boost.org/people/people.htm"><font face=
"Arial" color=
24 "#FFFFFF"><big>People
</big></font></a></td>
26 <td><a href=
"http://www.boost.org/more/faq.htm"><font face=
"Arial" color=
27 "#FFFFFF"><big>FAQ
</big></font></a></td>
29 <td><a href=
"../../more/index.htm"><font face=
"Arial" color=
30 "#FFFFFF"><big>More
</big></font></a></td>
34 <h1>Function Object Traits
</h1>
36 <p>The header
<a href=
"../../boost/functional.hpp">functional.hpp
</a>
37 provides two traits class templates for functions and function objects:
</p>
39 <table border=
"1" summary=
"">
49 <td valign=
"top" rowspan=
"4">
50 <tt>template
<typename
T
><br>
51 struct
unary_traits
</tt></td>
53 <td valign=
"top"><tt>function_type
</tt></td>
55 <td valign=
"top">The type of the function or function object itself
56 (i.e.,
<tt>T
</tt>).
</td>
60 <td valign=
"top"><tt>param_type
</tt></td>
62 <td valign=
"top">The type that should be used to pass the function or
63 function object as a parameter.
</td>
67 <td valign=
"top"><tt>result_type
</tt></td>
69 <td valign=
"top">The type returned by the function or function
74 <td valign=
"top"><tt>argument_type
</tt></td>
76 <td valign=
"top">The type of the argument to the function or function
81 <td valign=
"top" rowspan=
"5">
82 <tt>template
<typename
T
><br>
83 struct
binary_traits
</tt></td>
85 <td valign=
"top"><tt>function_type
</tt></td>
87 <td valign=
"top">The type of the function or function object itself
88 (i.e.,
<tt>T
</tt>).
</td>
92 <td valign=
"top"><tt>param_type
</tt></td>
94 <td valign=
"top">The type that should be used to pass the function or
95 function object as a parameter.
</td>
99 <td valign=
"top"><tt>result_type
</tt></td>
101 <td valign=
"top">The type returned by the function or function
106 <td valign=
"top"><tt>first_argument_type
</tt></td>
108 <td valign=
"top">The type of the first argument to the function or
109 function object.
</td>
113 <td valign=
"top"><tt>second_argument_type
</tt></td>
115 <td valign=
"top">The type of the second argument to the function or
116 function object.
</td>
122 <p><tt>unary_traits
</tt> should be instantiated with either a function
123 taking a single parameter, or an adaptable unary function object (i.e., a
124 class derived from
<tt>std::unary_function
</tt> or one which provides the
125 same typedefs). (See
§20.3.1 in the C++ Standard.)
</p>
127 <p><tt>binary_traits
</tt> should be instantiated with either a function
128 taking two parameters, or an adaptable binary function object (i.e., a
129 class derived from
<tt>std::binary_function
</tt> or one which provides the
130 same typedefs). (See
§20.3.1 in the C++ Standard.)
</p>
132 <p>The most common usage of these templates is in function object adapters,
133 thus allowing them to adapt plain functions as well as function objects.
134 You can do this by wherever you would normally write, for example,
</p>
138 typename Operation::argument_type
142 <p>simply writing
</p>
146 typename boost::unary_traits
<Operation
>::argument_type
152 <h3>Additional Types Defined
</h3>
154 <p>In addition to the standard result and argument typedefs, these traits
155 templates define two additional types.
</p>
157 <h4><tt>function_type
</tt></h4>
159 <p>This is the type of the function or function object, and can be used in
160 declarations such as
</p>
164 template
<class Predicate
>
165 class unary_negate : // ...
169 <strong>typename unary_traits
<Predicate
>::function_type
</strong> pred;
174 <p>If this typedef were not provided, it would not be possible to declare
175 <tt>pred
</tt> in a way that would allow
<tt>unary_negate
</tt> to be
176 instantiated with a function type (see the C++ Standard
§14.3.1
179 <h4><tt>param_type
</tt></h4>
181 <p>This is a type suitable for passing the function or function object as a
182 parameter to another function. For example,
</p>
186 template
<class Predicate
>
187 class unary_negate : // ...
190 explicit unary_negate(
<strong>typename unary_traits
<Predicate
>::param_type
</strong> x)
199 <p>Function objects are passed by reference to const; function pointers are
204 <p>This library uses these traits within all function object adapters,
205 theoretically rendering
<tt>ptr_fun
</tt> obsolete. However, third party
206 adapters probably won't take advantage of this mechanism, and so
207 <tt>ptr_fun
</tt> may still be required. Accordingly, this library also
208 provides
<a href=
"ptr_fun.html">improved versions of the standard function
209 pointer adapters
</a>.
</p>
211 <p>These traits templates will also not work with compilers that fail to
212 support partial specialisation of templates. With these compilers, the
213 traits templates can only be instantiated with adaptable function objects,
214 thus requiring
<tt>ptr_fun
</tt> to be used, even with the function object
215 adapters in this library.
</p>
218 <p><a href=
"http://validator.w3.org/check?uri=referer"><img border=
"0" src=
219 "../../doc/images/valid-html401.png" alt=
"Valid HTML 4.01 Transitional"
220 height=
"31" width=
"88"></a></p>
223 <!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->02
224 December,
2006<!--webbot bot="Timestamp" endspan i-checksum="38510" --></p>
226 <p><i>Copyright
© 2000 Cadenza New Zealand Ltd.
</i></p>
228 <p><i>Distributed under the Boost Software License, Version
1.0. (See
229 accompanying file
<a href=
"../../LICENSE_1_0.txt">LICENSE_1_0.txt
</a> or
231 "http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt
</a>)
</i></p>