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.
61 #ifndef __GLIBCPP_INTERNAL_FUNCTION_H
62 #define __GLIBCPP_INTERNAL_FUNCTION_H
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 #ifdef _GLIBCPP_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
);
373 /// One of the @link s20_3_6_binder binder functors@endlink.
374 template <class _Operation
, class _Tp
>
375 inline binder1st
<_Operation
>
376 bind1st(const _Operation
& __fn
, const _Tp
& __x
)
378 typedef typename
_Operation::first_argument_type _Arg1_type
;
379 return binder1st
<_Operation
>(__fn
, _Arg1_type(__x
));
382 /// One of the @link s20_3_6_binder binder functors@endlink.
383 template <class _Operation
>
385 : public unary_function
<typename
_Operation::first_argument_type
,
386 typename
_Operation::result_type
> {
389 typename
_Operation::second_argument_type value
;
391 binder2nd(const _Operation
& __x
,
392 const typename
_Operation::second_argument_type
& __y
)
393 : op(__x
), value(__y
) {}
394 typename
_Operation::result_type
395 operator()(const typename
_Operation::first_argument_type
& __x
) const {
396 return op(__x
, value
);
398 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
399 //109. Missing binders for non-const sequence elements
400 typename
_Operation::result_type
401 operator()(typename
_Operation::first_argument_type
& __x
) const {
402 return op(__x
, value
);
407 /// One of the @link s20_3_6_binder binder functors@endlink.
408 template <class _Operation
, class _Tp
>
409 inline binder2nd
<_Operation
>
410 bind2nd(const _Operation
& __fn
, const _Tp
& __x
)
412 typedef typename
_Operation::second_argument_type _Arg2_type
;
413 return binder2nd
<_Operation
>(__fn
, _Arg2_type(__x
));
417 // 20.3.7 adaptors pointers functions
418 /** @defgroup s20_3_7_adaptors Adaptors for pointers to functions
419 * The advantage of function objects over pointers to functions is that
420 * the objects in the standard library declare nested typedefs describing
421 * their argument and result types with uniform names (e.g., @c result_type
422 * from the base classes @c unary_function and @c binary_function).
423 * Sometimes those typedefs are required, not just optional.
425 * Adaptors are provided to turn pointers to unary (single-argument) and
426 * binary (double-argument) functions into function objects. The long-winded
427 * functor @c pointer_to_unary_function is constructed with a function
428 * pointer @c f, and its @c operator() called with argument @c x returns
429 * @c f(x). The functor @c pointer_to_binary_function does the same thing,
430 * but with a double-argument @c f and @c operator().
432 * The function @c ptr_fun takes a pointer-to-function @c f and constructs
433 * an instance of the appropriate functor.
437 /// One of the @link s20_3_7_adaptors adaptors for function pointers@endlink.
438 template <class _Arg
, class _Result
>
439 class pointer_to_unary_function
: public unary_function
<_Arg
, _Result
> {
441 _Result (*_M_ptr
)(_Arg
);
443 pointer_to_unary_function() {}
444 explicit pointer_to_unary_function(_Result (*__x
)(_Arg
)) : _M_ptr(__x
) {}
445 _Result
operator()(_Arg __x
) const { return _M_ptr(__x
); }
448 /// One of the @link s20_3_7_adaptors adaptors for function pointers@endlink.
449 template <class _Arg
, class _Result
>
450 inline pointer_to_unary_function
<_Arg
, _Result
> ptr_fun(_Result (*__x
)(_Arg
))
452 return pointer_to_unary_function
<_Arg
, _Result
>(__x
);
455 /// One of the @link s20_3_7_adaptors adaptors for function pointers@endlink.
456 template <class _Arg1
, class _Arg2
, class _Result
>
457 class pointer_to_binary_function
:
458 public binary_function
<_Arg1
,_Arg2
,_Result
> {
460 _Result (*_M_ptr
)(_Arg1
, _Arg2
);
462 pointer_to_binary_function() {}
463 explicit pointer_to_binary_function(_Result (*__x
)(_Arg1
, _Arg2
))
465 _Result
operator()(_Arg1 __x
, _Arg2 __y
) const {
466 return _M_ptr(__x
, __y
);
470 /// One of the @link s20_3_7_adaptors adaptors for function pointers@endlink.
471 template <class _Arg1
, class _Arg2
, class _Result
>
472 inline pointer_to_binary_function
<_Arg1
,_Arg2
,_Result
>
473 ptr_fun(_Result (*__x
)(_Arg1
, _Arg2
)) {
474 return pointer_to_binary_function
<_Arg1
,_Arg2
,_Result
>(__x
);
479 struct _Identity
: public unary_function
<_Tp
,_Tp
> {
480 _Tp
& operator()(_Tp
& __x
) const { return __x
; }
481 const _Tp
& operator()(const _Tp
& __x
) const { return __x
; }
484 template <class _Pair
>
485 struct _Select1st
: public unary_function
<_Pair
, typename
_Pair::first_type
> {
486 typename
_Pair::first_type
& operator()(_Pair
& __x
) const {
489 const typename
_Pair::first_type
& operator()(const _Pair
& __x
) const {
494 template <class _Pair
>
495 struct _Select2nd
: public unary_function
<_Pair
, typename
_Pair::second_type
>
497 typename
_Pair::second_type
& operator()(_Pair
& __x
) const {
500 const typename
_Pair::second_type
& operator()(const _Pair
& __x
) const {
505 // 20.3.8 adaptors pointers members
506 /** @defgroup s20_3_8_memadaptors Adaptors for pointers to members
507 * There are a total of 16 = 2^4 function objects in this family.
508 * (1) Member functions taking no arguments vs member functions taking
510 * (2) Call through pointer vs call through reference.
511 * (3) Member function with void return type vs member function with
512 * non-void return type.
513 * (4) Const vs non-const member function.
515 * Note that choice (3) is nothing more than a workaround: according
516 * to the draft, compilers should handle void and non-void the same way.
517 * This feature is not yet widely implemented, though. You can only use
518 * member functions returning void if your compiler supports partial
521 * All of this complexity is in the function objects themselves. You can
522 * ignore it by using the helper function mem_fun and mem_fun_ref,
523 * which create whichever type of adaptor is appropriate.
527 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
528 template <class _Ret
, class _Tp
>
529 class mem_fun_t
: public unary_function
<_Tp
*,_Ret
> {
531 explicit mem_fun_t(_Ret (_Tp::*__pf
)()) : _M_f(__pf
) {}
532 _Ret
operator()(_Tp
* __p
) const { return (__p
->*_M_f
)(); }
537 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
538 template <class _Ret
, class _Tp
>
539 class const_mem_fun_t
: public unary_function
<const _Tp
*,_Ret
> {
541 explicit const_mem_fun_t(_Ret (_Tp::*__pf
)() const) : _M_f(__pf
) {}
542 _Ret
operator()(const _Tp
* __p
) const { return (__p
->*_M_f
)(); }
544 _Ret (_Tp::*_M_f
)() const;
547 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
548 template <class _Ret
, class _Tp
>
549 class mem_fun_ref_t
: public unary_function
<_Tp
,_Ret
> {
551 explicit mem_fun_ref_t(_Ret (_Tp::*__pf
)()) : _M_f(__pf
) {}
552 _Ret
operator()(_Tp
& __r
) const { return (__r
.*_M_f
)(); }
557 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
558 template <class _Ret
, class _Tp
>
559 class const_mem_fun_ref_t
: public unary_function
<_Tp
,_Ret
> {
561 explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf
)() const) : _M_f(__pf
) {}
562 _Ret
operator()(const _Tp
& __r
) const { return (__r
.*_M_f
)(); }
564 _Ret (_Tp::*_M_f
)() const;
567 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
568 template <class _Ret
, class _Tp
, class _Arg
>
569 class mem_fun1_t
: public binary_function
<_Tp
*,_Arg
,_Ret
> {
571 explicit mem_fun1_t(_Ret (_Tp::*__pf
)(_Arg
)) : _M_f(__pf
) {}
572 _Ret
operator()(_Tp
* __p
, _Arg __x
) const { return (__p
->*_M_f
)(__x
); }
574 _Ret (_Tp::*_M_f
)(_Arg
);
577 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
578 template <class _Ret
, class _Tp
, class _Arg
>
579 class const_mem_fun1_t
: public binary_function
<const _Tp
*,_Arg
,_Ret
> {
581 explicit const_mem_fun1_t(_Ret (_Tp::*__pf
)(_Arg
) const) : _M_f(__pf
) {}
582 _Ret
operator()(const _Tp
* __p
, _Arg __x
) const
583 { return (__p
->*_M_f
)(__x
); }
585 _Ret (_Tp::*_M_f
)(_Arg
) const;
588 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
589 template <class _Ret
, class _Tp
, class _Arg
>
590 class mem_fun1_ref_t
: public binary_function
<_Tp
,_Arg
,_Ret
> {
592 explicit mem_fun1_ref_t(_Ret (_Tp::*__pf
)(_Arg
)) : _M_f(__pf
) {}
593 _Ret
operator()(_Tp
& __r
, _Arg __x
) const { return (__r
.*_M_f
)(__x
); }
595 _Ret (_Tp::*_M_f
)(_Arg
);
598 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
599 template <class _Ret
, class _Tp
, class _Arg
>
600 class const_mem_fun1_ref_t
: public binary_function
<_Tp
,_Arg
,_Ret
> {
602 explicit const_mem_fun1_ref_t(_Ret (_Tp::*__pf
)(_Arg
) const) : _M_f(__pf
) {}
603 _Ret
operator()(const _Tp
& __r
, _Arg __x
) const { return (__r
.*_M_f
)(__x
); }
605 _Ret (_Tp::*_M_f
)(_Arg
) const;
608 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
610 class mem_fun_t
<void, _Tp
> : public unary_function
<_Tp
*,void> {
612 explicit mem_fun_t(void (_Tp::*__pf
)()) : _M_f(__pf
) {}
613 void operator()(_Tp
* __p
) const { (__p
->*_M_f
)(); }
618 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
620 class const_mem_fun_t
<void, _Tp
> : public unary_function
<const _Tp
*,void> {
622 explicit const_mem_fun_t(void (_Tp::*__pf
)() const) : _M_f(__pf
) {}
623 void operator()(const _Tp
* __p
) const { (__p
->*_M_f
)(); }
625 void (_Tp::*_M_f
)() const;
628 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
630 class mem_fun_ref_t
<void, _Tp
> : public unary_function
<_Tp
,void> {
632 explicit mem_fun_ref_t(void (_Tp::*__pf
)()) : _M_f(__pf
) {}
633 void operator()(_Tp
& __r
) const { (__r
.*_M_f
)(); }
638 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
640 class const_mem_fun_ref_t
<void, _Tp
> : public unary_function
<_Tp
,void> {
642 explicit const_mem_fun_ref_t(void (_Tp::*__pf
)() const) : _M_f(__pf
) {}
643 void operator()(const _Tp
& __r
) const { (__r
.*_M_f
)(); }
645 void (_Tp::*_M_f
)() const;
648 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
649 template <class _Tp
, class _Arg
>
650 class mem_fun1_t
<void, _Tp
, _Arg
> : public binary_function
<_Tp
*,_Arg
,void> {
652 explicit mem_fun1_t(void (_Tp::*__pf
)(_Arg
)) : _M_f(__pf
) {}
653 void operator()(_Tp
* __p
, _Arg __x
) const { (__p
->*_M_f
)(__x
); }
655 void (_Tp::*_M_f
)(_Arg
);
658 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
659 template <class _Tp
, class _Arg
>
660 class const_mem_fun1_t
<void, _Tp
, _Arg
>
661 : public binary_function
<const _Tp
*,_Arg
,void> {
663 explicit const_mem_fun1_t(void (_Tp::*__pf
)(_Arg
) const) : _M_f(__pf
) {}
664 void operator()(const _Tp
* __p
, _Arg __x
) const { (__p
->*_M_f
)(__x
); }
666 void (_Tp::*_M_f
)(_Arg
) const;
669 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
670 template <class _Tp
, class _Arg
>
671 class mem_fun1_ref_t
<void, _Tp
, _Arg
>
672 : public binary_function
<_Tp
,_Arg
,void> {
674 explicit mem_fun1_ref_t(void (_Tp::*__pf
)(_Arg
)) : _M_f(__pf
) {}
675 void operator()(_Tp
& __r
, _Arg __x
) const { (__r
.*_M_f
)(__x
); }
677 void (_Tp::*_M_f
)(_Arg
);
680 /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
681 template <class _Tp
, class _Arg
>
682 class const_mem_fun1_ref_t
<void, _Tp
, _Arg
>
683 : public binary_function
<_Tp
,_Arg
,void> {
685 explicit const_mem_fun1_ref_t(void (_Tp::*__pf
)(_Arg
) const) : _M_f(__pf
) {}
686 void operator()(const _Tp
& __r
, _Arg __x
) const { (__r
.*_M_f
)(__x
); }
688 void (_Tp::*_M_f
)(_Arg
) const;
692 // Mem_fun adaptor helper functions. There are only two:
693 // mem_fun and mem_fun_ref.
695 template <class _Ret
, class _Tp
>
696 inline mem_fun_t
<_Ret
,_Tp
> mem_fun(_Ret (_Tp::*__f
)())
697 { return mem_fun_t
<_Ret
,_Tp
>(__f
); }
699 template <class _Ret
, class _Tp
>
700 inline const_mem_fun_t
<_Ret
,_Tp
> mem_fun(_Ret (_Tp::*__f
)() const)
701 { return const_mem_fun_t
<_Ret
,_Tp
>(__f
); }
703 template <class _Ret
, class _Tp
>
704 inline mem_fun_ref_t
<_Ret
,_Tp
> mem_fun_ref(_Ret (_Tp::*__f
)())
705 { return mem_fun_ref_t
<_Ret
,_Tp
>(__f
); }
707 template <class _Ret
, class _Tp
>
708 inline const_mem_fun_ref_t
<_Ret
,_Tp
> mem_fun_ref(_Ret (_Tp::*__f
)() const)
709 { return const_mem_fun_ref_t
<_Ret
,_Tp
>(__f
); }
711 template <class _Ret
, class _Tp
, class _Arg
>
712 inline mem_fun1_t
<_Ret
,_Tp
,_Arg
> mem_fun(_Ret (_Tp::*__f
)(_Arg
))
713 { return mem_fun1_t
<_Ret
,_Tp
,_Arg
>(__f
); }
715 template <class _Ret
, class _Tp
, class _Arg
>
716 inline const_mem_fun1_t
<_Ret
,_Tp
,_Arg
> mem_fun(_Ret (_Tp::*__f
)(_Arg
) const)
717 { return const_mem_fun1_t
<_Ret
,_Tp
,_Arg
>(__f
); }
719 template <class _Ret
, class _Tp
, class _Arg
>
720 inline mem_fun1_ref_t
<_Ret
,_Tp
,_Arg
> mem_fun_ref(_Ret (_Tp::*__f
)(_Arg
))
721 { return mem_fun1_ref_t
<_Ret
,_Tp
,_Arg
>(__f
); }
723 template <class _Ret
, class _Tp
, class _Arg
>
724 inline const_mem_fun1_ref_t
<_Ret
,_Tp
,_Arg
>
725 mem_fun_ref(_Ret (_Tp::*__f
)(_Arg
) const)
726 { return const_mem_fun1_ref_t
<_Ret
,_Tp
,_Arg
>(__f
); }
732 #endif /* __GLIBCPP_INTERNAL_FUNCTION_H */