Chris@16
|
1 // ------------------------------------------------------------------------------
|
Chris@16
|
2 // Copyright (c) 2000 Cadenza New Zealand Ltd
|
Chris@16
|
3 // Distributed under the Boost Software License, Version 1.0. (See accompany-
|
Chris@16
|
4 // ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
5 // ------------------------------------------------------------------------------
|
Chris@16
|
6 // Boost functional.hpp header file
|
Chris@16
|
7 // See http://www.boost.org/libs/functional for documentation.
|
Chris@16
|
8 // ------------------------------------------------------------------------------
|
Chris@101
|
9 // $Id$
|
Chris@16
|
10 // ------------------------------------------------------------------------------
|
Chris@16
|
11
|
Chris@16
|
12 #ifndef BOOST_FUNCTIONAL_HPP
|
Chris@16
|
13 #define BOOST_FUNCTIONAL_HPP
|
Chris@16
|
14
|
Chris@16
|
15 #include <boost/config.hpp>
|
Chris@16
|
16 #include <boost/call_traits.hpp>
|
Chris@16
|
17 #include <functional>
|
Chris@16
|
18
|
Chris@16
|
19 namespace boost
|
Chris@16
|
20 {
|
Chris@16
|
21 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
Chris@16
|
22 // --------------------------------------------------------------------------
|
Chris@16
|
23 // The following traits classes allow us to avoid the need for ptr_fun
|
Chris@16
|
24 // because the types of arguments and the result of a function can be
|
Chris@16
|
25 // deduced.
|
Chris@16
|
26 //
|
Chris@16
|
27 // In addition to the standard types defined in unary_function and
|
Chris@16
|
28 // binary_function, we add
|
Chris@16
|
29 //
|
Chris@16
|
30 // - function_type, the type of the function or function object itself.
|
Chris@16
|
31 //
|
Chris@16
|
32 // - param_type, the type that should be used for passing the function or
|
Chris@16
|
33 // function object as an argument.
|
Chris@16
|
34 // --------------------------------------------------------------------------
|
Chris@16
|
35 namespace detail
|
Chris@16
|
36 {
|
Chris@16
|
37 template <class Operation>
|
Chris@16
|
38 struct unary_traits_imp;
|
Chris@16
|
39
|
Chris@16
|
40 template <class Operation>
|
Chris@16
|
41 struct unary_traits_imp<Operation*>
|
Chris@16
|
42 {
|
Chris@16
|
43 typedef Operation function_type;
|
Chris@16
|
44 typedef const function_type & param_type;
|
Chris@16
|
45 typedef typename Operation::result_type result_type;
|
Chris@16
|
46 typedef typename Operation::argument_type argument_type;
|
Chris@16
|
47 };
|
Chris@16
|
48
|
Chris@16
|
49 template <class R, class A>
|
Chris@16
|
50 struct unary_traits_imp<R(*)(A)>
|
Chris@16
|
51 {
|
Chris@16
|
52 typedef R (*function_type)(A);
|
Chris@16
|
53 typedef R (*param_type)(A);
|
Chris@16
|
54 typedef R result_type;
|
Chris@16
|
55 typedef A argument_type;
|
Chris@16
|
56 };
|
Chris@16
|
57
|
Chris@16
|
58 template <class Operation>
|
Chris@16
|
59 struct binary_traits_imp;
|
Chris@16
|
60
|
Chris@16
|
61 template <class Operation>
|
Chris@16
|
62 struct binary_traits_imp<Operation*>
|
Chris@16
|
63 {
|
Chris@16
|
64 typedef Operation function_type;
|
Chris@16
|
65 typedef const function_type & param_type;
|
Chris@16
|
66 typedef typename Operation::result_type result_type;
|
Chris@16
|
67 typedef typename Operation::first_argument_type first_argument_type;
|
Chris@16
|
68 typedef typename Operation::second_argument_type second_argument_type;
|
Chris@16
|
69 };
|
Chris@16
|
70
|
Chris@16
|
71 template <class R, class A1, class A2>
|
Chris@16
|
72 struct binary_traits_imp<R(*)(A1,A2)>
|
Chris@16
|
73 {
|
Chris@16
|
74 typedef R (*function_type)(A1,A2);
|
Chris@16
|
75 typedef R (*param_type)(A1,A2);
|
Chris@16
|
76 typedef R result_type;
|
Chris@16
|
77 typedef A1 first_argument_type;
|
Chris@16
|
78 typedef A2 second_argument_type;
|
Chris@16
|
79 };
|
Chris@16
|
80 } // namespace detail
|
Chris@16
|
81
|
Chris@16
|
82 template <class Operation>
|
Chris@16
|
83 struct unary_traits
|
Chris@16
|
84 {
|
Chris@16
|
85 typedef typename detail::unary_traits_imp<Operation*>::function_type function_type;
|
Chris@16
|
86 typedef typename detail::unary_traits_imp<Operation*>::param_type param_type;
|
Chris@16
|
87 typedef typename detail::unary_traits_imp<Operation*>::result_type result_type;
|
Chris@16
|
88 typedef typename detail::unary_traits_imp<Operation*>::argument_type argument_type;
|
Chris@16
|
89 };
|
Chris@16
|
90
|
Chris@16
|
91 template <class R, class A>
|
Chris@16
|
92 struct unary_traits<R(*)(A)>
|
Chris@16
|
93 {
|
Chris@16
|
94 typedef R (*function_type)(A);
|
Chris@16
|
95 typedef R (*param_type)(A);
|
Chris@16
|
96 typedef R result_type;
|
Chris@16
|
97 typedef A argument_type;
|
Chris@16
|
98 };
|
Chris@16
|
99
|
Chris@16
|
100 template <class Operation>
|
Chris@16
|
101 struct binary_traits
|
Chris@16
|
102 {
|
Chris@16
|
103 typedef typename detail::binary_traits_imp<Operation*>::function_type function_type;
|
Chris@16
|
104 typedef typename detail::binary_traits_imp<Operation*>::param_type param_type;
|
Chris@16
|
105 typedef typename detail::binary_traits_imp<Operation*>::result_type result_type;
|
Chris@16
|
106 typedef typename detail::binary_traits_imp<Operation*>::first_argument_type first_argument_type;
|
Chris@16
|
107 typedef typename detail::binary_traits_imp<Operation*>::second_argument_type second_argument_type;
|
Chris@16
|
108 };
|
Chris@16
|
109
|
Chris@16
|
110 template <class R, class A1, class A2>
|
Chris@16
|
111 struct binary_traits<R(*)(A1,A2)>
|
Chris@16
|
112 {
|
Chris@16
|
113 typedef R (*function_type)(A1,A2);
|
Chris@16
|
114 typedef R (*param_type)(A1,A2);
|
Chris@16
|
115 typedef R result_type;
|
Chris@16
|
116 typedef A1 first_argument_type;
|
Chris@16
|
117 typedef A2 second_argument_type;
|
Chris@16
|
118 };
|
Chris@16
|
119 #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
Chris@16
|
120 // --------------------------------------------------------------------------
|
Chris@16
|
121 // If we have no partial specialisation available, decay to a situation
|
Chris@16
|
122 // that is no worse than in the Standard, i.e., ptr_fun will be required.
|
Chris@16
|
123 // --------------------------------------------------------------------------
|
Chris@16
|
124
|
Chris@16
|
125 template <class Operation>
|
Chris@16
|
126 struct unary_traits
|
Chris@16
|
127 {
|
Chris@16
|
128 typedef Operation function_type;
|
Chris@16
|
129 typedef const Operation& param_type;
|
Chris@16
|
130 typedef typename Operation::result_type result_type;
|
Chris@16
|
131 typedef typename Operation::argument_type argument_type;
|
Chris@16
|
132 };
|
Chris@16
|
133
|
Chris@16
|
134 template <class Operation>
|
Chris@16
|
135 struct binary_traits
|
Chris@16
|
136 {
|
Chris@16
|
137 typedef Operation function_type;
|
Chris@16
|
138 typedef const Operation & param_type;
|
Chris@16
|
139 typedef typename Operation::result_type result_type;
|
Chris@16
|
140 typedef typename Operation::first_argument_type first_argument_type;
|
Chris@16
|
141 typedef typename Operation::second_argument_type second_argument_type;
|
Chris@16
|
142 };
|
Chris@16
|
143 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
Chris@16
|
144
|
Chris@16
|
145 // --------------------------------------------------------------------------
|
Chris@16
|
146 // unary_negate, not1
|
Chris@16
|
147 // --------------------------------------------------------------------------
|
Chris@16
|
148 template <class Predicate>
|
Chris@16
|
149 class unary_negate
|
Chris@16
|
150 : public std::unary_function<typename unary_traits<Predicate>::argument_type,bool>
|
Chris@16
|
151 {
|
Chris@16
|
152 public:
|
Chris@16
|
153 explicit unary_negate(typename unary_traits<Predicate>::param_type x)
|
Chris@16
|
154 :
|
Chris@16
|
155 pred(x)
|
Chris@16
|
156 {}
|
Chris@16
|
157 bool operator()(typename call_traits<typename unary_traits<Predicate>::argument_type>::param_type x) const
|
Chris@16
|
158 {
|
Chris@16
|
159 return !pred(x);
|
Chris@16
|
160 }
|
Chris@16
|
161 private:
|
Chris@16
|
162 typename unary_traits<Predicate>::function_type pred;
|
Chris@16
|
163 };
|
Chris@16
|
164
|
Chris@16
|
165 template <class Predicate>
|
Chris@16
|
166 unary_negate<Predicate> not1(const Predicate &pred)
|
Chris@16
|
167 {
|
Chris@16
|
168 // The cast is to placate Borland C++Builder in certain circumstances.
|
Chris@16
|
169 // I don't think it should be necessary.
|
Chris@16
|
170 return unary_negate<Predicate>((typename unary_traits<Predicate>::param_type)pred);
|
Chris@16
|
171 }
|
Chris@16
|
172
|
Chris@16
|
173 template <class Predicate>
|
Chris@16
|
174 unary_negate<Predicate> not1(Predicate &pred)
|
Chris@16
|
175 {
|
Chris@16
|
176 return unary_negate<Predicate>(pred);
|
Chris@16
|
177 }
|
Chris@16
|
178
|
Chris@16
|
179 // --------------------------------------------------------------------------
|
Chris@16
|
180 // binary_negate, not2
|
Chris@16
|
181 // --------------------------------------------------------------------------
|
Chris@16
|
182 template <class Predicate>
|
Chris@16
|
183 class binary_negate
|
Chris@16
|
184 : public std::binary_function<typename binary_traits<Predicate>::first_argument_type,
|
Chris@16
|
185 typename binary_traits<Predicate>::second_argument_type,
|
Chris@16
|
186 bool>
|
Chris@16
|
187 {
|
Chris@16
|
188 public:
|
Chris@16
|
189 explicit binary_negate(typename binary_traits<Predicate>::param_type x)
|
Chris@16
|
190 :
|
Chris@16
|
191 pred(x)
|
Chris@16
|
192 {}
|
Chris@16
|
193 bool operator()(typename call_traits<typename binary_traits<Predicate>::first_argument_type>::param_type x,
|
Chris@16
|
194 typename call_traits<typename binary_traits<Predicate>::second_argument_type>::param_type y) const
|
Chris@16
|
195 {
|
Chris@16
|
196 return !pred(x,y);
|
Chris@16
|
197 }
|
Chris@16
|
198 private:
|
Chris@16
|
199 typename binary_traits<Predicate>::function_type pred;
|
Chris@16
|
200 };
|
Chris@16
|
201
|
Chris@16
|
202 template <class Predicate>
|
Chris@16
|
203 binary_negate<Predicate> not2(const Predicate &pred)
|
Chris@16
|
204 {
|
Chris@16
|
205 // The cast is to placate Borland C++Builder in certain circumstances.
|
Chris@16
|
206 // I don't think it should be necessary.
|
Chris@16
|
207 return binary_negate<Predicate>((typename binary_traits<Predicate>::param_type)pred);
|
Chris@16
|
208 }
|
Chris@16
|
209
|
Chris@16
|
210 template <class Predicate>
|
Chris@16
|
211 binary_negate<Predicate> not2(Predicate &pred)
|
Chris@16
|
212 {
|
Chris@16
|
213 return binary_negate<Predicate>(pred);
|
Chris@16
|
214 }
|
Chris@16
|
215
|
Chris@16
|
216 // --------------------------------------------------------------------------
|
Chris@16
|
217 // binder1st, bind1st
|
Chris@16
|
218 // --------------------------------------------------------------------------
|
Chris@16
|
219 template <class Operation>
|
Chris@16
|
220 class binder1st
|
Chris@16
|
221 : public std::unary_function<typename binary_traits<Operation>::second_argument_type,
|
Chris@16
|
222 typename binary_traits<Operation>::result_type>
|
Chris@16
|
223 {
|
Chris@16
|
224 public:
|
Chris@16
|
225 binder1st(typename binary_traits<Operation>::param_type x,
|
Chris@16
|
226 typename call_traits<typename binary_traits<Operation>::first_argument_type>::param_type y)
|
Chris@16
|
227 :
|
Chris@16
|
228 op(x), value(y)
|
Chris@16
|
229 {}
|
Chris@16
|
230
|
Chris@16
|
231 typename binary_traits<Operation>::result_type
|
Chris@16
|
232 operator()(typename call_traits<typename binary_traits<Operation>::second_argument_type>::param_type x) const
|
Chris@16
|
233 {
|
Chris@16
|
234 return op(value, x);
|
Chris@16
|
235 }
|
Chris@16
|
236
|
Chris@16
|
237 protected:
|
Chris@16
|
238 typename binary_traits<Operation>::function_type op;
|
Chris@16
|
239 typename binary_traits<Operation>::first_argument_type value;
|
Chris@16
|
240 };
|
Chris@16
|
241
|
Chris@16
|
242 template <class Operation>
|
Chris@16
|
243 inline binder1st<Operation> bind1st(const Operation &op,
|
Chris@16
|
244 typename call_traits<
|
Chris@16
|
245 typename binary_traits<Operation>::first_argument_type
|
Chris@16
|
246 >::param_type x)
|
Chris@16
|
247 {
|
Chris@16
|
248 // The cast is to placate Borland C++Builder in certain circumstances.
|
Chris@16
|
249 // I don't think it should be necessary.
|
Chris@16
|
250 return binder1st<Operation>((typename binary_traits<Operation>::param_type)op, x);
|
Chris@16
|
251 }
|
Chris@16
|
252
|
Chris@16
|
253 template <class Operation>
|
Chris@16
|
254 inline binder1st<Operation> bind1st(Operation &op,
|
Chris@16
|
255 typename call_traits<
|
Chris@16
|
256 typename binary_traits<Operation>::first_argument_type
|
Chris@16
|
257 >::param_type x)
|
Chris@16
|
258 {
|
Chris@16
|
259 return binder1st<Operation>(op, x);
|
Chris@16
|
260 }
|
Chris@16
|
261
|
Chris@16
|
262 // --------------------------------------------------------------------------
|
Chris@16
|
263 // binder2nd, bind2nd
|
Chris@16
|
264 // --------------------------------------------------------------------------
|
Chris@16
|
265 template <class Operation>
|
Chris@16
|
266 class binder2nd
|
Chris@16
|
267 : public std::unary_function<typename binary_traits<Operation>::first_argument_type,
|
Chris@16
|
268 typename binary_traits<Operation>::result_type>
|
Chris@16
|
269 {
|
Chris@16
|
270 public:
|
Chris@16
|
271 binder2nd(typename binary_traits<Operation>::param_type x,
|
Chris@16
|
272 typename call_traits<typename binary_traits<Operation>::second_argument_type>::param_type y)
|
Chris@16
|
273 :
|
Chris@16
|
274 op(x), value(y)
|
Chris@16
|
275 {}
|
Chris@16
|
276
|
Chris@16
|
277 typename binary_traits<Operation>::result_type
|
Chris@16
|
278 operator()(typename call_traits<typename binary_traits<Operation>::first_argument_type>::param_type x) const
|
Chris@16
|
279 {
|
Chris@16
|
280 return op(x, value);
|
Chris@16
|
281 }
|
Chris@16
|
282
|
Chris@16
|
283 protected:
|
Chris@16
|
284 typename binary_traits<Operation>::function_type op;
|
Chris@16
|
285 typename binary_traits<Operation>::second_argument_type value;
|
Chris@16
|
286 };
|
Chris@16
|
287
|
Chris@16
|
288 template <class Operation>
|
Chris@16
|
289 inline binder2nd<Operation> bind2nd(const Operation &op,
|
Chris@16
|
290 typename call_traits<
|
Chris@16
|
291 typename binary_traits<Operation>::second_argument_type
|
Chris@16
|
292 >::param_type x)
|
Chris@16
|
293 {
|
Chris@16
|
294 // The cast is to placate Borland C++Builder in certain circumstances.
|
Chris@16
|
295 // I don't think it should be necessary.
|
Chris@16
|
296 return binder2nd<Operation>((typename binary_traits<Operation>::param_type)op, x);
|
Chris@16
|
297 }
|
Chris@16
|
298
|
Chris@16
|
299 template <class Operation>
|
Chris@16
|
300 inline binder2nd<Operation> bind2nd(Operation &op,
|
Chris@16
|
301 typename call_traits<
|
Chris@16
|
302 typename binary_traits<Operation>::second_argument_type
|
Chris@16
|
303 >::param_type x)
|
Chris@16
|
304 {
|
Chris@16
|
305 return binder2nd<Operation>(op, x);
|
Chris@16
|
306 }
|
Chris@16
|
307
|
Chris@16
|
308 // --------------------------------------------------------------------------
|
Chris@16
|
309 // mem_fun, etc
|
Chris@16
|
310 // --------------------------------------------------------------------------
|
Chris@16
|
311 template <class S, class T>
|
Chris@16
|
312 class mem_fun_t : public std::unary_function<T*, S>
|
Chris@16
|
313 {
|
Chris@16
|
314 public:
|
Chris@16
|
315 explicit mem_fun_t(S (T::*p)())
|
Chris@16
|
316 :
|
Chris@16
|
317 ptr(p)
|
Chris@16
|
318 {}
|
Chris@16
|
319 S operator()(T* p) const
|
Chris@16
|
320 {
|
Chris@16
|
321 return (p->*ptr)();
|
Chris@16
|
322 }
|
Chris@16
|
323 private:
|
Chris@16
|
324 S (T::*ptr)();
|
Chris@16
|
325 };
|
Chris@16
|
326
|
Chris@16
|
327 template <class S, class T, class A>
|
Chris@16
|
328 class mem_fun1_t : public std::binary_function<T*, A, S>
|
Chris@16
|
329 {
|
Chris@16
|
330 public:
|
Chris@16
|
331 explicit mem_fun1_t(S (T::*p)(A))
|
Chris@16
|
332 :
|
Chris@16
|
333 ptr(p)
|
Chris@16
|
334 {}
|
Chris@16
|
335 S operator()(T* p, typename call_traits<A>::param_type x) const
|
Chris@16
|
336 {
|
Chris@16
|
337 return (p->*ptr)(x);
|
Chris@16
|
338 }
|
Chris@16
|
339 private:
|
Chris@16
|
340 S (T::*ptr)(A);
|
Chris@16
|
341 };
|
Chris@16
|
342
|
Chris@16
|
343 template <class S, class T>
|
Chris@16
|
344 class const_mem_fun_t : public std::unary_function<const T*, S>
|
Chris@16
|
345 {
|
Chris@16
|
346 public:
|
Chris@16
|
347 explicit const_mem_fun_t(S (T::*p)() const)
|
Chris@16
|
348 :
|
Chris@16
|
349 ptr(p)
|
Chris@16
|
350 {}
|
Chris@16
|
351 S operator()(const T* p) const
|
Chris@16
|
352 {
|
Chris@16
|
353 return (p->*ptr)();
|
Chris@16
|
354 }
|
Chris@16
|
355 private:
|
Chris@16
|
356 S (T::*ptr)() const;
|
Chris@16
|
357 };
|
Chris@16
|
358
|
Chris@16
|
359 template <class S, class T, class A>
|
Chris@16
|
360 class const_mem_fun1_t : public std::binary_function<const T*, A, S>
|
Chris@16
|
361 {
|
Chris@16
|
362 public:
|
Chris@16
|
363 explicit const_mem_fun1_t(S (T::*p)(A) const)
|
Chris@16
|
364 :
|
Chris@16
|
365 ptr(p)
|
Chris@16
|
366 {}
|
Chris@16
|
367 S operator()(const T* p, typename call_traits<A>::param_type x) const
|
Chris@16
|
368 {
|
Chris@16
|
369 return (p->*ptr)(x);
|
Chris@16
|
370 }
|
Chris@16
|
371 private:
|
Chris@16
|
372 S (T::*ptr)(A) const;
|
Chris@16
|
373 };
|
Chris@16
|
374
|
Chris@16
|
375 template<class S, class T>
|
Chris@16
|
376 inline mem_fun_t<S,T> mem_fun(S (T::*f)())
|
Chris@16
|
377 {
|
Chris@16
|
378 return mem_fun_t<S,T>(f);
|
Chris@16
|
379 }
|
Chris@16
|
380
|
Chris@16
|
381 template<class S, class T, class A>
|
Chris@16
|
382 inline mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A))
|
Chris@16
|
383 {
|
Chris@16
|
384 return mem_fun1_t<S,T,A>(f);
|
Chris@16
|
385 }
|
Chris@16
|
386
|
Chris@16
|
387 #ifndef BOOST_NO_POINTER_TO_MEMBER_CONST
|
Chris@16
|
388 template<class S, class T>
|
Chris@16
|
389 inline const_mem_fun_t<S,T> mem_fun(S (T::*f)() const)
|
Chris@16
|
390 {
|
Chris@16
|
391 return const_mem_fun_t<S,T>(f);
|
Chris@16
|
392 }
|
Chris@16
|
393
|
Chris@16
|
394 template<class S, class T, class A>
|
Chris@16
|
395 inline const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const)
|
Chris@16
|
396 {
|
Chris@16
|
397 return const_mem_fun1_t<S,T,A>(f);
|
Chris@16
|
398 }
|
Chris@16
|
399 #endif // BOOST_NO_POINTER_TO_MEMBER_CONST
|
Chris@16
|
400
|
Chris@16
|
401 // --------------------------------------------------------------------------
|
Chris@16
|
402 // mem_fun_ref, etc
|
Chris@16
|
403 // --------------------------------------------------------------------------
|
Chris@16
|
404 template <class S, class T>
|
Chris@16
|
405 class mem_fun_ref_t : public std::unary_function<T&, S>
|
Chris@16
|
406 {
|
Chris@16
|
407 public:
|
Chris@16
|
408 explicit mem_fun_ref_t(S (T::*p)())
|
Chris@16
|
409 :
|
Chris@16
|
410 ptr(p)
|
Chris@16
|
411 {}
|
Chris@16
|
412 S operator()(T& p) const
|
Chris@16
|
413 {
|
Chris@16
|
414 return (p.*ptr)();
|
Chris@16
|
415 }
|
Chris@16
|
416 private:
|
Chris@16
|
417 S (T::*ptr)();
|
Chris@16
|
418 };
|
Chris@16
|
419
|
Chris@16
|
420 template <class S, class T, class A>
|
Chris@16
|
421 class mem_fun1_ref_t : public std::binary_function<T&, A, S>
|
Chris@16
|
422 {
|
Chris@16
|
423 public:
|
Chris@16
|
424 explicit mem_fun1_ref_t(S (T::*p)(A))
|
Chris@16
|
425 :
|
Chris@16
|
426 ptr(p)
|
Chris@16
|
427 {}
|
Chris@16
|
428 S operator()(T& p, typename call_traits<A>::param_type x) const
|
Chris@16
|
429 {
|
Chris@16
|
430 return (p.*ptr)(x);
|
Chris@16
|
431 }
|
Chris@16
|
432 private:
|
Chris@16
|
433 S (T::*ptr)(A);
|
Chris@16
|
434 };
|
Chris@16
|
435
|
Chris@16
|
436 template <class S, class T>
|
Chris@16
|
437 class const_mem_fun_ref_t : public std::unary_function<const T&, S>
|
Chris@16
|
438 {
|
Chris@16
|
439 public:
|
Chris@16
|
440 explicit const_mem_fun_ref_t(S (T::*p)() const)
|
Chris@16
|
441 :
|
Chris@16
|
442 ptr(p)
|
Chris@16
|
443 {}
|
Chris@16
|
444
|
Chris@16
|
445 S operator()(const T &p) const
|
Chris@16
|
446 {
|
Chris@16
|
447 return (p.*ptr)();
|
Chris@16
|
448 }
|
Chris@16
|
449 private:
|
Chris@16
|
450 S (T::*ptr)() const;
|
Chris@16
|
451 };
|
Chris@16
|
452
|
Chris@16
|
453 template <class S, class T, class A>
|
Chris@16
|
454 class const_mem_fun1_ref_t : public std::binary_function<const T&, A, S>
|
Chris@16
|
455 {
|
Chris@16
|
456 public:
|
Chris@16
|
457 explicit const_mem_fun1_ref_t(S (T::*p)(A) const)
|
Chris@16
|
458 :
|
Chris@16
|
459 ptr(p)
|
Chris@16
|
460 {}
|
Chris@16
|
461
|
Chris@16
|
462 S operator()(const T& p, typename call_traits<A>::param_type x) const
|
Chris@16
|
463 {
|
Chris@16
|
464 return (p.*ptr)(x);
|
Chris@16
|
465 }
|
Chris@16
|
466 private:
|
Chris@16
|
467 S (T::*ptr)(A) const;
|
Chris@16
|
468 };
|
Chris@16
|
469
|
Chris@16
|
470 template<class S, class T>
|
Chris@16
|
471 inline mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)())
|
Chris@16
|
472 {
|
Chris@16
|
473 return mem_fun_ref_t<S,T>(f);
|
Chris@16
|
474 }
|
Chris@16
|
475
|
Chris@16
|
476 template<class S, class T, class A>
|
Chris@16
|
477 inline mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A))
|
Chris@16
|
478 {
|
Chris@16
|
479 return mem_fun1_ref_t<S,T,A>(f);
|
Chris@16
|
480 }
|
Chris@16
|
481
|
Chris@16
|
482 #ifndef BOOST_NO_POINTER_TO_MEMBER_CONST
|
Chris@16
|
483 template<class S, class T>
|
Chris@16
|
484 inline const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const)
|
Chris@16
|
485 {
|
Chris@16
|
486 return const_mem_fun_ref_t<S,T>(f);
|
Chris@16
|
487 }
|
Chris@16
|
488
|
Chris@16
|
489 template<class S, class T, class A>
|
Chris@16
|
490 inline const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const)
|
Chris@16
|
491 {
|
Chris@16
|
492 return const_mem_fun1_ref_t<S,T,A>(f);
|
Chris@16
|
493 }
|
Chris@16
|
494 #endif // BOOST_NO_POINTER_TO_MEMBER_CONST
|
Chris@16
|
495
|
Chris@16
|
496 // --------------------------------------------------------------------------
|
Chris@16
|
497 // ptr_fun
|
Chris@16
|
498 // --------------------------------------------------------------------------
|
Chris@16
|
499 template <class Arg, class Result>
|
Chris@16
|
500 class pointer_to_unary_function : public std::unary_function<Arg,Result>
|
Chris@16
|
501 {
|
Chris@16
|
502 public:
|
Chris@16
|
503 explicit pointer_to_unary_function(Result (*f)(Arg))
|
Chris@16
|
504 :
|
Chris@16
|
505 func(f)
|
Chris@16
|
506 {}
|
Chris@16
|
507
|
Chris@16
|
508 Result operator()(typename call_traits<Arg>::param_type x) const
|
Chris@16
|
509 {
|
Chris@16
|
510 return func(x);
|
Chris@16
|
511 }
|
Chris@16
|
512
|
Chris@16
|
513 private:
|
Chris@16
|
514 Result (*func)(Arg);
|
Chris@16
|
515 };
|
Chris@16
|
516
|
Chris@16
|
517 template <class Arg, class Result>
|
Chris@16
|
518 inline pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg))
|
Chris@16
|
519 {
|
Chris@16
|
520 return pointer_to_unary_function<Arg,Result>(f);
|
Chris@16
|
521 }
|
Chris@16
|
522
|
Chris@16
|
523 template <class Arg1, class Arg2, class Result>
|
Chris@16
|
524 class pointer_to_binary_function : public std::binary_function<Arg1,Arg2,Result>
|
Chris@16
|
525 {
|
Chris@16
|
526 public:
|
Chris@16
|
527 explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2))
|
Chris@16
|
528 :
|
Chris@16
|
529 func(f)
|
Chris@16
|
530 {}
|
Chris@16
|
531
|
Chris@16
|
532 Result operator()(typename call_traits<Arg1>::param_type x, typename call_traits<Arg2>::param_type y) const
|
Chris@16
|
533 {
|
Chris@16
|
534 return func(x,y);
|
Chris@16
|
535 }
|
Chris@16
|
536
|
Chris@16
|
537 private:
|
Chris@16
|
538 Result (*func)(Arg1, Arg2);
|
Chris@16
|
539 };
|
Chris@16
|
540
|
Chris@16
|
541 template <class Arg1, class Arg2, class Result>
|
Chris@16
|
542 inline pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1, Arg2))
|
Chris@16
|
543 {
|
Chris@16
|
544 return pointer_to_binary_function<Arg1,Arg2,Result>(f);
|
Chris@16
|
545 }
|
Chris@16
|
546 } // namespace boost
|
Chris@16
|
547
|
Chris@16
|
548 #endif
|