1 // Functor implementations -*- C++ -*-
3 // Copyright (C) 2001, 2002 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
33 * Hewlett-Packard Company
35 * Permission to use, copy, modify, distribute and sell this software
36 * and its documentation for any purpose is hereby granted without fee,
37 * provided that the above copyright notice appear in all copies and
38 * that both that copyright notice and this permission notice appear
39 * in supporting documentation. Hewlett-Packard Company makes no
40 * representations about the suitability of this software for any
41 * purpose. It is provided "as is" without express or implied warranty.
44 * Copyright (c) 1996-1998
45 * Silicon Graphics Computer Systems, Inc.
47 * Permission to use, copy, modify, distribute and sell this software
48 * and its documentation for any purpose is hereby granted without fee,
49 * provided that the above copyright notice appear in all copies and
50 * that both that copyright notice and this permission notice appear
51 * in supporting documentation. Silicon Graphics makes no
52 * representations about the suitability of this software for any
53 * purpose. It is provided "as is" without express or implied warranty.
56 /** @file stl_function.h
57 * This is an internal header file, included by other library headers.
58 * You should not attempt to use it directly.
66 // 20.3.1 base classes
67 /** @defgroup s20_3_1_base Functor Base Classes
68 * Function objects, or @e functors, are objects with an @c operator()
69 * defined and accessible. They can be passed as arguments to algorithm
70 * templates and used in place of a function pointer. Not only is the
71 * resulting expressiveness of the library increased, but the generated
72 * code can be more efficient than what you might write by hand. When we
73 * refer to "functors," then, generally we include function pointers in
74 * the description as well.
76 * Often, functors are only created as temporaries passed to algorithm
77 * calls, rather than being created as named variables.
79 * Two examples taken from the standard itself follow. To perform a
80 * by-element addition of two vectors @c a and @c b containing @c double,
81 * and put the result in @c a, use
83 * transform (a.begin(), a.end(), b.begin(), a.begin(), plus<double>());
85 * To negate every element in @c a, use
87 * transform(a.begin(), a.end(), a.begin(), negate<double>());
89 * The addition and negation functions will be inlined directly.
91 * The standard functiors are derived from structs named @c unary_function
92 * and @c binary_function. These two classes contain nothing but typedefs,
93 * to aid in generic (template) programming. If you write your own
94 * functors, you might consider doing the same.
99 * This is one of the @link s20_3_1_base functor base classes@endlink.
101 template <class _Arg
, class _Result
>
102 struct unary_function
{
103 typedef _Arg argument_type
; ///< @c argument_type is the type of the argument (no surprises here)
104 typedef _Result result_type
; ///< @c result_type is the return type
108 * This is one of the @link s20_3_1_base functor base classes@endlink.
110 template <class _Arg1
, class _Arg2
, class _Result
>
111 struct binary_function
{
112 typedef _Arg1 first_argument_type
; ///< the type of the first argument (no surprises here)
113 typedef _Arg2 second_argument_type
; ///< the type of the second argument
114 typedef _Result result_type
; ///< type of the return type
119 /** @defgroup s20_3_2_arithmetic Arithmetic Classes
120 * Because basic math often needs to be done during an algorithm, the library
121 * provides functors for those operations. See the documentation for
122 * @link s20_3_1_base the base classes@endlink for examples of their use.
126 /// One of the @link s20_3_2_arithmetic math functors@endlink.
128 struct plus
: public binary_function
<_Tp
,_Tp
,_Tp
> {
129 _Tp
operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
+ __y
; }
132 /// One of the @link s20_3_2_arithmetic math functors@endlink.
134 struct minus
: public binary_function
<_Tp
,_Tp
,_Tp
> {
135 _Tp
operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
- __y
; }
138 /// One of the @link s20_3_2_arithmetic math functors@endlink.
140 struct multiplies
: public binary_function
<_Tp
,_Tp
,_Tp
> {
141 _Tp
operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
* __y
; }
144 /// One of the @link s20_3_2_arithmetic math functors@endlink.
146 struct divides
: public binary_function
<_Tp
,_Tp
,_Tp
> {
147 _Tp
operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
/ __y
; }
150 /// One of the @link s20_3_2_arithmetic math functors@endlink.
152 struct modulus
: public binary_function
<_Tp
,_Tp
,_Tp
>
154 _Tp
operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
% __y
; }
157 /// One of the @link s20_3_2_arithmetic math functors@endlink.
159 struct negate
: public unary_function
<_Tp
,_Tp
>
161 _Tp
operator()(const _Tp
& __x
) const { return -__x
; }
165 // 20.3.3 comparisons
166 /** @defgroup s20_3_3_comparisons Comparison Classes
167 * The library provides six wrapper functors for all the basic comparisons
172 /// One of the @link s20_3_3_comparisons comparison functors@endlink.
174 struct equal_to
: public binary_function
<_Tp
,_Tp
,bool>
176 bool operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
== __y
; }
179 /// One of the @link s20_3_3_comparisons comparison functors@endlink.
181 struct not_equal_to
: public binary_function
<_Tp
,_Tp
,bool>
183 bool operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
!= __y
; }
186 /// One of the @link s20_3_3_comparisons comparison functors@endlink.
188 struct greater
: public binary_function
<_Tp
,_Tp
,bool>
190 bool operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
> __y
; }
193 /// One of the @link s20_3_3_comparisons comparison functors@endlink.
195 struct less
: public binary_function
<_Tp
,_Tp
,bool>
197 bool operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
< __y
; }
200 /// One of the @link s20_3_3_comparisons comparison functors@endlink.
202 struct greater_equal
: public binary_function
<_Tp
,_Tp
,bool>
204 bool operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
>= __y
; }
207 /// One of the @link s20_3_3_comparisons comparison functors@endlink.
209 struct less_equal
: public binary_function
<_Tp
,_Tp
,bool>
211 bool operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
<= __y
; }
215 // 20.3.4 logical operations
216 /** @defgroup s20_3_4_logical Boolean Operations Classes
217 * Here are wrapper functors for Boolean operations: @c &&, @c ||, and @c !.
221 /// One of the @link s20_3_4_logical Boolean operations functors@endlink.
223 struct logical_and
: public binary_function
<_Tp
,_Tp
,bool>
225 bool operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
&& __y
; }
228 /// One of the @link s20_3_4_logical Boolean operations functors@endlink.
230 struct logical_or
: public binary_function
<_Tp
,_Tp
,bool>
232 bool operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
|| __y
; }
235 /// One of the @link s20_3_4_logical Boolean operations functors@endlink.
237 struct logical_not
: public unary_function
<_Tp
,bool>
239 bool operator()(const _Tp
& __x
) const { return !__x
; }
244 /** @defgroup s20_3_5_negators Negators
245 * The functions @c not1 and @c not2 each take a predicate functor
246 * and return an instance of @c unary_negate or
247 * @c binary_negate, respectively. These classes are functors whose
248 * @c operator() performs the stored predicate function and then returns
249 * the negation of the result.
251 * For example, given a vector of integers and a trivial predicate,
253 * struct IntGreaterThanThree
254 * : public std::unary_function<int, bool>
256 * bool operator() (int x) { return x > 3; }
259 * std::find_if (v.begin(), v.end(), not1(IntGreaterThanThree()));
261 * The call to @c find_if will locate the first index (i) of @c v for which
262 * "!(v[i] > 3)" is true.
264 * The not1/unary_negate combination works on predicates taking a single
265 * argument. The not2/binary_negate combination works on predicates which
266 * take two arguments.
270 /// One of the @link s20_3_5_negators negation functors@endlink.
271 template <class _Predicate
>
273 : public unary_function
<typename
_Predicate::argument_type
, bool> {
277 explicit unary_negate(const _Predicate
& __x
) : _M_pred(__x
) {}
278 bool operator()(const typename
_Predicate::argument_type
& __x
) const {
279 return !_M_pred(__x
);
283 /// One of the @link s20_3_5_negators negation functors@endlink.
284 template <class _Predicate
>
285 inline unary_negate
<_Predicate
>
286 not1(const _Predicate
& __pred
)
288 return unary_negate
<_Predicate
>(__pred
);
291 /// One of the @link s20_3_5_negators negation functors@endlink.
292 template <class _Predicate
>
294 : public binary_function
<typename
_Predicate::first_argument_type
,
295 typename
_Predicate::second_argument_type
,
300 explicit binary_negate(const _Predicate
& __x
) : _M_pred(__x
) {}
301 bool operator()(const typename
_Predicate::first_argument_type
& __x
,
302 const typename
_Predicate::second_argument_type
& __y
) const
304 return !_M_pred(__x
, __y
);
308 /// One of the @link s20_3_5_negators negation functors@endlink.
309 template <class _Predicate
>
310 inline binary_negate
<_Predicate
>
311 not2(const _Predicate
& __pred
)
313 return binary_negate
<_Predicate
>(__pred
);
318 /** @defgroup s20_3_6_binder Binder Classes
319 * Binders turn functions/functors with two arguments into functors with
320 * a single argument, storing an argument to be applied later. For
321 * example, an variable @c B of type @c binder1st is constructed from a functor
322 * @c f and an argument @c x. Later, B's @c operator() is called with a
323 * single argument @c y. The return value is the value of @c f(x,y).
324 * @c B can be "called" with various arguments (y1, y2, ...) and will in
325 * turn call @c f(x,y1), @c f(x,y2), ...
327 * The function @c bind1st is provided to save some typing. It takes the
328 * function and an argument as parameters, and returns an instance of
331 * The type @c binder2nd and its creator function @c bind2nd do the same
332 * thing, but the stored argument is passed as the second parameter instead
333 * of the first, e.g., @c bind2nd(std::minus<float>,1.3) will create a
334 * functor whose @c operator() accepts a floating-point number, subtracts
335 * 1.3 from it, and returns the result. (If @c bind1st had been used,
336 * the functor would perform "1.3 - x" instead.
338 * Creator-wrapper functions like @c bind1st are intended to be used in
339 * calling algorithms. Their return values will be temporary objects.
340 * (The goal is to not require you to type names like
341 * @c std::binder1st<std::plus<int>> for declaring a variable to hold the
342 * return value from @c bind1st(std::plus<int>,5).
344 * These become more useful when combined with the composition functions.
348 /// One of the @link s20_3_6_binder binder functors@endlink.
349 template <class _Operation
>
351 : public unary_function
<typename
_Operation::second_argument_type
,
352 typename
_Operation::result_type
> {
355 typename
_Operation::first_argument_type value
;
357 binder1st(const _Operation
& __x
,
358 const typename
_Operation::first_argument_type
& __y
)
359 : op(__x
), value(__y
) {}
360 typename
_Operation::result_type
361 operator()(const typename
_Operation::second_argument_type
& __x
) const {
362 return op(value
, __x
);
364 // _GLIBCXX_RESOLVE_LIB_DEFECTS
365 // 109. Missing binders for non-const sequence elements
366 typename
_Operation::result_type
367 operator()(typename
_Operation::second_argument_type
& __x
) const {
368 return op(value
, __x
);
372 /// One of the @link s20_3_6_binder binder functors@endlink.
373 template <class _Operation
, class _Tp
>
374 inline binder1st
<_Operation
>
375 bind1st(const _Operation
& __fn
, const _Tp
& __x
)
377 typedef typename
_Operation::first_argument_type _Arg1_type
;
378 return binder1st
<_Operation
>(__fn
, _Arg1_type(__x
));
381 /// One of the @link s20_3_6_binder binder functors@endlink.
382 template <class _Operation
>
384 : public unary_function
<typename
_Operation::first_argument_type
,
385 typename
_Operation::result_type
> {
388 typename
_Operation::second_argument_type value
;
390 binder2nd(const _Operation
& __x
,
391 const typename
_Operation::second_argument_type
& __y
)
392 : op(__x
), value(__y
) {}
393 typename
_Operation::result_type
394 operator()(const typename
_Operation::first_argument_type
& __x
) const {
395 return op(__x
, value
);
397 // _GLIBCXX_RESOLVE_LIB_DEFECTS
398 // 109. Missing binders for non-const sequence elements
399 typename
_Operation::result_type
400 operator()(typename
_Operation::first_argument_type
& __x
) const {
401 return op(__x
, value
);
405 /// One of the @link s20_3_6_binder binder functors@endlink.
406 template <class _Operation
, class _Tp
>
407 inline binder2nd
<_Operation
>
408 bind2nd(const _Operation
& __fn
, const _Tp
& __x
)
410 typedef typename
_Operation::second_argument_type _Arg2_type
;
411 return binder2nd
<_Operation
>(__fn
, _Arg2_type(__x
));
415 // 20.3.7 adaptors pointers functions
416 /** @defgroup s20_3_7_adaptors Adaptors for pointers to functions
417 * The advantage of function objects over pointers to functions is that
418 * the objects in the standard library declare nested typedefs describing
419 * their argument and result types with uniform names (e.g., @c result_type
420 * from the base classes @c unary_function and @c binary_function).
421 * Sometimes those typedefs are required, not just optional.
423 * Adaptors are provided to turn pointers to unary (single-argument) and
424 * binary (double-argument) functions into function objects. The long-winded
425 * functor @c pointer_to_unary_function is constructed with a function
426 * pointer @c f, and its @c operator() called with argument @c x returns
427 * @c f(x). The functor @c pointer_to_binary_function does the same thing,
428 * but with a double-argument @c f and @c operator().
430 * The function @c ptr_fun takes a pointer-to-function @c f and constructs
431 * an instance of the appropriate functor.
435 /// One of the @link s20_3_7_adaptors adaptors for function pointers@endlink.
436 template <class _Arg
, class _Result
>
437 class pointer_to_unary_function
: public unary_function
<_Arg
, _Result
> {
439 _Result (*_M_ptr
)(_Arg
);
441 pointer_to_unary_function() {}
442 explicit pointer_to_unary_function(_Result (*__x
)(_Arg
)) : _M_ptr(__x
) {}
443 _Result
operator()(_Arg __x
) const { return _M_ptr(__x
); }
446 /// One of the @link s20_3_7_adaptors adaptors for function pointers@endlink.
447 template <class _Arg
, class _Result
>
448 inline pointer_to_unary_function
<_Arg
, _Result
> ptr_fun(_Result (*__x
)(_Arg
))
450 return pointer_to_unary_function
<_Arg
, _Result
>(__x
);
453 /// One of the @link s20_3_7_adaptors adaptors for function pointers@endlink.
454 template <class _Arg1
, class _Arg2
, class _Result
>
455 class pointer_to_binary_function
:
456 public binary_function
<_Arg1
,_Arg2
,_Result
> {
458 _Result (*_M_ptr
)(_Arg1
, _Arg2
);
460 pointer_to_binary_function() {}
461 explicit pointer_to_binary_function(_Result (*__x
)(_Arg1
, _Arg2
))
463 _Result
operator()(_Arg1 __x
, _Arg2 __y
) const {
464 return _M_ptr(__x
, __y
);
468 /// One of the @link s20_3_7_adaptors adaptors for function pointers@endlink.
469 template <class _Arg1
, class _Arg2
, class _Result
>
470 inline pointer_to_binary_function
<_Arg1
,_Arg2
,_Result
>
471 ptr_fun(_Result (*__x
)(_Arg1
, _Arg2
)) {
472 return pointer_to_binary_function
<_Arg1
,_Arg2
,_Result
>(__x
);
477 struct _Identity
: public unary_function
<_Tp
,_Tp
> {
478 _Tp
& operator()(_Tp
& __x
) const { return __x
; }
479 const _Tp
& operator()(const _Tp
& __x
) const { return __x
; }
482 template <class _Pair
>
483 struct _Select1st
: public unary_function
<_Pair
, typename
_Pair::first_type
> {
484 typename
_Pair::first_type
& operator()(_Pair
& __x
) const {
487 const typename
_Pair::first_type
& operator()(const _Pair
& __x
) const {
492 template <class _Pair
>
493 struct _Select2nd
: public unary_function
<_Pair
, typename
_Pair::second_type
>
495 typename
_Pair::second_type
& operator()(_Pair
& __x
) const {
498 const typename
_Pair::second_type
& operator()(const _Pair
& __x
) const {
503 // 20.3.8 adaptors pointers members
504 /** @defgroup s20_3_8_memadaptors Adaptors for pointers to members
505 * There are a total of 16 = 2^4 function objects in this family.
506 * (1) Member functions taking no arguments vs member functions taking
508 * (2) Call through pointer vs call through reference.
509 * (3) Member function with void return type vs member function with
510 * non-void return type.
511 * (4) Const vs non-const member function.
513 * Note that choice (3) is nothing more than a workaround: according
514 * to the draft, compilers should handle void and non-void the same way.
515 * This feature is not yet widely implemented, though. You can only use
516 * member functions returning void if your compiler supports partial
519 * All of this complexity is in the function objects themselves. You can
520 * ignore it by using the helper function mem_fun and mem_fun_ref,
521 * which create whichever type of adaptor is appropriate.
525 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
526 template <class _Ret
, class _Tp
>
527 class mem_fun_t
: public unary_function
<_Tp
*,_Ret
> {
529 explicit mem_fun_t(_Ret (_Tp::*__pf
)()) : _M_f(__pf
) {}
530 _Ret
operator()(_Tp
* __p
) const { return (__p
->*_M_f
)(); }
535 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
536 template <class _Ret
, class _Tp
>
537 class const_mem_fun_t
: public unary_function
<const _Tp
*,_Ret
> {
539 explicit const_mem_fun_t(_Ret (_Tp::*__pf
)() const) : _M_f(__pf
) {}
540 _Ret
operator()(const _Tp
* __p
) const { return (__p
->*_M_f
)(); }
542 _Ret (_Tp::*_M_f
)() const;
545 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
546 template <class _Ret
, class _Tp
>
547 class mem_fun_ref_t
: public unary_function
<_Tp
,_Ret
> {
549 explicit mem_fun_ref_t(_Ret (_Tp::*__pf
)()) : _M_f(__pf
) {}
550 _Ret
operator()(_Tp
& __r
) const { return (__r
.*_M_f
)(); }
555 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
556 template <class _Ret
, class _Tp
>
557 class const_mem_fun_ref_t
: public unary_function
<_Tp
,_Ret
> {
559 explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf
)() const) : _M_f(__pf
) {}
560 _Ret
operator()(const _Tp
& __r
) const { return (__r
.*_M_f
)(); }
562 _Ret (_Tp::*_M_f
)() const;
565 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
566 template <class _Ret
, class _Tp
, class _Arg
>
567 class mem_fun1_t
: public binary_function
<_Tp
*,_Arg
,_Ret
> {
569 explicit mem_fun1_t(_Ret (_Tp::*__pf
)(_Arg
)) : _M_f(__pf
) {}
570 _Ret
operator()(_Tp
* __p
, _Arg __x
) const { return (__p
->*_M_f
)(__x
); }
572 _Ret (_Tp::*_M_f
)(_Arg
);
575 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
576 template <class _Ret
, class _Tp
, class _Arg
>
577 class const_mem_fun1_t
: public binary_function
<const _Tp
*,_Arg
,_Ret
> {
579 explicit const_mem_fun1_t(_Ret (_Tp::*__pf
)(_Arg
) const) : _M_f(__pf
) {}
580 _Ret
operator()(const _Tp
* __p
, _Arg __x
) const
581 { return (__p
->*_M_f
)(__x
); }
583 _Ret (_Tp::*_M_f
)(_Arg
) const;
586 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
587 template <class _Ret
, class _Tp
, class _Arg
>
588 class mem_fun1_ref_t
: public binary_function
<_Tp
,_Arg
,_Ret
> {
590 explicit mem_fun1_ref_t(_Ret (_Tp::*__pf
)(_Arg
)) : _M_f(__pf
) {}
591 _Ret
operator()(_Tp
& __r
, _Arg __x
) const { return (__r
.*_M_f
)(__x
); }
593 _Ret (_Tp::*_M_f
)(_Arg
);
596 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
597 template <class _Ret
, class _Tp
, class _Arg
>
598 class const_mem_fun1_ref_t
: public binary_function
<_Tp
,_Arg
,_Ret
> {
600 explicit const_mem_fun1_ref_t(_Ret (_Tp::*__pf
)(_Arg
) const) : _M_f(__pf
) {}
601 _Ret
operator()(const _Tp
& __r
, _Arg __x
) const { return (__r
.*_M_f
)(__x
); }
603 _Ret (_Tp::*_M_f
)(_Arg
) const;
606 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
608 class mem_fun_t
<void, _Tp
> : public unary_function
<_Tp
*,void> {
610 explicit mem_fun_t(void (_Tp::*__pf
)()) : _M_f(__pf
) {}
611 void operator()(_Tp
* __p
) const { (__p
->*_M_f
)(); }
616 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
618 class const_mem_fun_t
<void, _Tp
> : public unary_function
<const _Tp
*,void> {
620 explicit const_mem_fun_t(void (_Tp::*__pf
)() const) : _M_f(__pf
) {}
621 void operator()(const _Tp
* __p
) const { (__p
->*_M_f
)(); }
623 void (_Tp::*_M_f
)() const;
626 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
628 class mem_fun_ref_t
<void, _Tp
> : public unary_function
<_Tp
,void> {
630 explicit mem_fun_ref_t(void (_Tp::*__pf
)()) : _M_f(__pf
) {}
631 void operator()(_Tp
& __r
) const { (__r
.*_M_f
)(); }
636 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
638 class const_mem_fun_ref_t
<void, _Tp
> : public unary_function
<_Tp
,void> {
640 explicit const_mem_fun_ref_t(void (_Tp::*__pf
)() const) : _M_f(__pf
) {}
641 void operator()(const _Tp
& __r
) const { (__r
.*_M_f
)(); }
643 void (_Tp::*_M_f
)() const;
646 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
647 template <class _Tp
, class _Arg
>
648 class mem_fun1_t
<void, _Tp
, _Arg
> : public binary_function
<_Tp
*,_Arg
,void> {
650 explicit mem_fun1_t(void (_Tp::*__pf
)(_Arg
)) : _M_f(__pf
) {}
651 void operator()(_Tp
* __p
, _Arg __x
) const { (__p
->*_M_f
)(__x
); }
653 void (_Tp::*_M_f
)(_Arg
);
656 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
657 template <class _Tp
, class _Arg
>
658 class const_mem_fun1_t
<void, _Tp
, _Arg
>
659 : public binary_function
<const _Tp
*,_Arg
,void> {
661 explicit const_mem_fun1_t(void (_Tp::*__pf
)(_Arg
) const) : _M_f(__pf
) {}
662 void operator()(const _Tp
* __p
, _Arg __x
) const { (__p
->*_M_f
)(__x
); }
664 void (_Tp::*_M_f
)(_Arg
) const;
667 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
668 template <class _Tp
, class _Arg
>
669 class mem_fun1_ref_t
<void, _Tp
, _Arg
>
670 : public binary_function
<_Tp
,_Arg
,void> {
672 explicit mem_fun1_ref_t(void (_Tp::*__pf
)(_Arg
)) : _M_f(__pf
) {}
673 void operator()(_Tp
& __r
, _Arg __x
) const { (__r
.*_M_f
)(__x
); }
675 void (_Tp::*_M_f
)(_Arg
);
678 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
679 template <class _Tp
, class _Arg
>
680 class const_mem_fun1_ref_t
<void, _Tp
, _Arg
>
681 : public binary_function
<_Tp
,_Arg
,void> {
683 explicit const_mem_fun1_ref_t(void (_Tp::*__pf
)(_Arg
) const) : _M_f(__pf
) {}
684 void operator()(const _Tp
& __r
, _Arg __x
) const { (__r
.*_M_f
)(__x
); }
686 void (_Tp::*_M_f
)(_Arg
) const;
690 // Mem_fun adaptor helper functions. There are only two:
691 // mem_fun and mem_fun_ref.
693 template <class _Ret
, class _Tp
>
694 inline mem_fun_t
<_Ret
,_Tp
> mem_fun(_Ret (_Tp::*__f
)())
695 { return mem_fun_t
<_Ret
,_Tp
>(__f
); }
697 template <class _Ret
, class _Tp
>
698 inline const_mem_fun_t
<_Ret
,_Tp
> mem_fun(_Ret (_Tp::*__f
)() const)
699 { return const_mem_fun_t
<_Ret
,_Tp
>(__f
); }
701 template <class _Ret
, class _Tp
>
702 inline mem_fun_ref_t
<_Ret
,_Tp
> mem_fun_ref(_Ret (_Tp::*__f
)())
703 { return mem_fun_ref_t
<_Ret
,_Tp
>(__f
); }
705 template <class _Ret
, class _Tp
>
706 inline const_mem_fun_ref_t
<_Ret
,_Tp
> mem_fun_ref(_Ret (_Tp::*__f
)() const)
707 { return const_mem_fun_ref_t
<_Ret
,_Tp
>(__f
); }
709 template <class _Ret
, class _Tp
, class _Arg
>
710 inline mem_fun1_t
<_Ret
,_Tp
,_Arg
> mem_fun(_Ret (_Tp::*__f
)(_Arg
))
711 { return mem_fun1_t
<_Ret
,_Tp
,_Arg
>(__f
); }
713 template <class _Ret
, class _Tp
, class _Arg
>
714 inline const_mem_fun1_t
<_Ret
,_Tp
,_Arg
> mem_fun(_Ret (_Tp::*__f
)(_Arg
) const)
715 { return const_mem_fun1_t
<_Ret
,_Tp
,_Arg
>(__f
); }
717 template <class _Ret
, class _Tp
, class _Arg
>
718 inline mem_fun1_ref_t
<_Ret
,_Tp
,_Arg
> mem_fun_ref(_Ret (_Tp::*__f
)(_Arg
))
719 { return mem_fun1_ref_t
<_Ret
,_Tp
,_Arg
>(__f
); }
721 template <class _Ret
, class _Tp
, class _Arg
>
722 inline const_mem_fun1_ref_t
<_Ret
,_Tp
,_Arg
>
723 mem_fun_ref(_Ret (_Tp::*__f
)(_Arg
) const)
724 { return const_mem_fun1_ref_t
<_Ret
,_Tp
,_Arg
>(__f
); }
730 #endif /* _FUNCTION_H */