1 // Functor implementations -*- C++ -*-
3 // Copyright (C) 2001 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 /* NOTE: This is an internal header file, included by other STL headers.
57 * You should not attempt to use it directly.
60 #ifndef __SGI_STL_INTERNAL_FUNCTION_H
61 #define __SGI_STL_INTERNAL_FUNCTION_H
66 template <class _Arg
, class _Result
>
67 struct unary_function
{
68 typedef _Arg argument_type
;
69 typedef _Result result_type
;
72 template <class _Arg1
, class _Arg2
, class _Result
>
73 struct binary_function
{
74 typedef _Arg1 first_argument_type
;
75 typedef _Arg2 second_argument_type
;
76 typedef _Result result_type
;
80 struct plus
: public binary_function
<_Tp
,_Tp
,_Tp
> {
81 _Tp
operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
+ __y
; }
85 struct minus
: public binary_function
<_Tp
,_Tp
,_Tp
> {
86 _Tp
operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
- __y
; }
90 struct multiplies
: public binary_function
<_Tp
,_Tp
,_Tp
> {
91 _Tp
operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
* __y
; }
95 struct divides
: public binary_function
<_Tp
,_Tp
,_Tp
> {
96 _Tp
operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
/ __y
; }
99 // identity_element (not part of the C++ standard).
101 template <class _Tp
> inline _Tp
identity_element(plus
<_Tp
>) {
104 template <class _Tp
> inline _Tp
identity_element(multiplies
<_Tp
>) {
109 struct modulus
: public binary_function
<_Tp
,_Tp
,_Tp
>
111 _Tp
operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
% __y
; }
115 struct negate
: public unary_function
<_Tp
,_Tp
>
117 _Tp
operator()(const _Tp
& __x
) const { return -__x
; }
121 struct equal_to
: public binary_function
<_Tp
,_Tp
,bool>
123 bool operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
== __y
; }
127 struct not_equal_to
: public binary_function
<_Tp
,_Tp
,bool>
129 bool operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
!= __y
; }
133 struct greater
: public binary_function
<_Tp
,_Tp
,bool>
135 bool operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
> __y
; }
139 struct less
: public binary_function
<_Tp
,_Tp
,bool>
141 bool operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
< __y
; }
145 struct greater_equal
: public binary_function
<_Tp
,_Tp
,bool>
147 bool operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
>= __y
; }
151 struct less_equal
: public binary_function
<_Tp
,_Tp
,bool>
153 bool operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
<= __y
; }
157 struct logical_and
: public binary_function
<_Tp
,_Tp
,bool>
159 bool operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
&& __y
; }
163 struct logical_or
: public binary_function
<_Tp
,_Tp
,bool>
165 bool operator()(const _Tp
& __x
, const _Tp
& __y
) const { return __x
|| __y
; }
169 struct logical_not
: public unary_function
<_Tp
,bool>
171 bool operator()(const _Tp
& __x
) const { return !__x
; }
174 template <class _Predicate
>
176 : public unary_function
<typename
_Predicate::argument_type
, bool> {
180 explicit unary_negate(const _Predicate
& __x
) : _M_pred(__x
) {}
181 bool operator()(const typename
_Predicate::argument_type
& __x
) const {
182 return !_M_pred(__x
);
186 template <class _Predicate
>
187 inline unary_negate
<_Predicate
>
188 not1(const _Predicate
& __pred
)
190 return unary_negate
<_Predicate
>(__pred
);
193 template <class _Predicate
>
195 : public binary_function
<typename
_Predicate::first_argument_type
,
196 typename
_Predicate::second_argument_type
,
201 explicit binary_negate(const _Predicate
& __x
) : _M_pred(__x
) {}
202 bool operator()(const typename
_Predicate::first_argument_type
& __x
,
203 const typename
_Predicate::second_argument_type
& __y
) const
205 return !_M_pred(__x
, __y
);
209 template <class _Predicate
>
210 inline binary_negate
<_Predicate
>
211 not2(const _Predicate
& __pred
)
213 return binary_negate
<_Predicate
>(__pred
);
216 template <class _Operation
>
218 : public unary_function
<typename
_Operation::second_argument_type
,
219 typename
_Operation::result_type
> {
222 typename
_Operation::first_argument_type value
;
224 binder1st(const _Operation
& __x
,
225 const typename
_Operation::first_argument_type
& __y
)
226 : op(__x
), value(__y
) {}
227 typename
_Operation::result_type
228 operator()(const typename
_Operation::second_argument_type
& __x
) const {
229 return op(value
, __x
);
231 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
232 // 109. Missing binders for non-const sequence elements
233 typename
_Operation::result_type
234 operator()(typename
_Operation::second_argument_type
& __x
) const {
235 return op(value
, __x
);
240 template <class _Operation
, class _Tp
>
241 inline binder1st
<_Operation
>
242 bind1st(const _Operation
& __fn
, const _Tp
& __x
)
244 typedef typename
_Operation::first_argument_type _Arg1_type
;
245 return binder1st
<_Operation
>(__fn
, _Arg1_type(__x
));
248 template <class _Operation
>
250 : public unary_function
<typename
_Operation::first_argument_type
,
251 typename
_Operation::result_type
> {
254 typename
_Operation::second_argument_type value
;
256 binder2nd(const _Operation
& __x
,
257 const typename
_Operation::second_argument_type
& __y
)
258 : op(__x
), value(__y
) {}
259 typename
_Operation::result_type
260 operator()(const typename
_Operation::first_argument_type
& __x
) const {
261 return op(__x
, value
);
263 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
264 // 109. Missing binders for non-const sequence elements
265 typename
_Operation::result_type
266 operator()(typename
_Operation::first_argument_type
& __x
) const {
267 return op(__x
, value
);
272 template <class _Operation
, class _Tp
>
273 inline binder2nd
<_Operation
>
274 bind2nd(const _Operation
& __fn
, const _Tp
& __x
)
276 typedef typename
_Operation::second_argument_type _Arg2_type
;
277 return binder2nd
<_Operation
>(__fn
, _Arg2_type(__x
));
280 // unary_compose and binary_compose (extensions, not part of the standard).
282 template <class _Operation1
, class _Operation2
>
284 : public unary_function
<typename
_Operation2::argument_type
,
285 typename
_Operation1::result_type
>
291 unary_compose(const _Operation1
& __x
, const _Operation2
& __y
)
292 : _M_fn1(__x
), _M_fn2(__y
) {}
293 typename
_Operation1::result_type
294 operator()(const typename
_Operation2::argument_type
& __x
) const {
295 return _M_fn1(_M_fn2(__x
));
299 template <class _Operation1
, class _Operation2
>
300 inline unary_compose
<_Operation1
,_Operation2
>
301 compose1(const _Operation1
& __fn1
, const _Operation2
& __fn2
)
303 return unary_compose
<_Operation1
,_Operation2
>(__fn1
, __fn2
);
306 template <class _Operation1
, class _Operation2
, class _Operation3
>
308 : public unary_function
<typename
_Operation2::argument_type
,
309 typename
_Operation1::result_type
> {
315 binary_compose(const _Operation1
& __x
, const _Operation2
& __y
,
316 const _Operation3
& __z
)
317 : _M_fn1(__x
), _M_fn2(__y
), _M_fn3(__z
) { }
318 typename
_Operation1::result_type
319 operator()(const typename
_Operation2::argument_type
& __x
) const {
320 return _M_fn1(_M_fn2(__x
), _M_fn3(__x
));
324 template <class _Operation1
, class _Operation2
, class _Operation3
>
325 inline binary_compose
<_Operation1
, _Operation2
, _Operation3
>
326 compose2(const _Operation1
& __fn1
, const _Operation2
& __fn2
,
327 const _Operation3
& __fn3
)
329 return binary_compose
<_Operation1
,_Operation2
,_Operation3
>
330 (__fn1
, __fn2
, __fn3
);
333 template <class _Arg
, class _Result
>
334 class pointer_to_unary_function
: public unary_function
<_Arg
, _Result
> {
336 _Result (*_M_ptr
)(_Arg
);
338 pointer_to_unary_function() {}
339 explicit pointer_to_unary_function(_Result (*__x
)(_Arg
)) : _M_ptr(__x
) {}
340 _Result
operator()(_Arg __x
) const { return _M_ptr(__x
); }
343 template <class _Arg
, class _Result
>
344 inline pointer_to_unary_function
<_Arg
, _Result
> ptr_fun(_Result (*__x
)(_Arg
))
346 return pointer_to_unary_function
<_Arg
, _Result
>(__x
);
349 template <class _Arg1
, class _Arg2
, class _Result
>
350 class pointer_to_binary_function
:
351 public binary_function
<_Arg1
,_Arg2
,_Result
> {
353 _Result (*_M_ptr
)(_Arg1
, _Arg2
);
355 pointer_to_binary_function() {}
356 explicit pointer_to_binary_function(_Result (*__x
)(_Arg1
, _Arg2
))
358 _Result
operator()(_Arg1 __x
, _Arg2 __y
) const {
359 return _M_ptr(__x
, __y
);
363 template <class _Arg1
, class _Arg2
, class _Result
>
364 inline pointer_to_binary_function
<_Arg1
,_Arg2
,_Result
>
365 ptr_fun(_Result (*__x
)(_Arg1
, _Arg2
)) {
366 return pointer_to_binary_function
<_Arg1
,_Arg2
,_Result
>(__x
);
369 // identity is an extensions: it is not part of the standard.
371 struct _Identity
: public unary_function
<_Tp
,_Tp
> {
372 _Tp
& operator()(_Tp
& __x
) const { return __x
; }
373 const _Tp
& operator()(const _Tp
& __x
) const { return __x
; }
376 template <class _Tp
> struct identity
: public _Identity
<_Tp
> {};
378 // select1st and select2nd are extensions: they are not part of the standard.
379 template <class _Pair
>
380 struct _Select1st
: public unary_function
<_Pair
, typename
_Pair::first_type
> {
381 typename
_Pair::first_type
& operator()(_Pair
& __x
) const {
384 const typename
_Pair::first_type
& operator()(const _Pair
& __x
) const {
389 template <class _Pair
>
390 struct _Select2nd
: public unary_function
<_Pair
, typename
_Pair::second_type
>
392 typename
_Pair::second_type
& operator()(_Pair
& __x
) const {
395 const typename
_Pair::second_type
& operator()(const _Pair
& __x
) const {
400 template <class _Pair
> struct select1st
: public _Select1st
<_Pair
> {};
401 template <class _Pair
> struct select2nd
: public _Select2nd
<_Pair
> {};
403 // project1st and project2nd are extensions: they are not part of the standard
404 template <class _Arg1
, class _Arg2
>
405 struct _Project1st
: public binary_function
<_Arg1
, _Arg2
, _Arg1
> {
406 _Arg1
operator()(const _Arg1
& __x
, const _Arg2
&) const { return __x
; }
409 template <class _Arg1
, class _Arg2
>
410 struct _Project2nd
: public binary_function
<_Arg1
, _Arg2
, _Arg2
> {
411 _Arg2
operator()(const _Arg1
&, const _Arg2
& __y
) const { return __y
; }
414 template <class _Arg1
, class _Arg2
>
415 struct project1st
: public _Project1st
<_Arg1
, _Arg2
> {};
417 template <class _Arg1
, class _Arg2
>
418 struct project2nd
: public _Project2nd
<_Arg1
, _Arg2
> {};
420 // constant_void_fun, constant_unary_fun, and constant_binary_fun are
421 // extensions: they are not part of the standard. (The same, of course,
422 // is true of the helper functions constant0, constant1, and constant2.)
424 template <class _Result
>
425 struct _Constant_void_fun
{
426 typedef _Result result_type
;
429 _Constant_void_fun(const result_type
& __v
) : _M_val(__v
) {}
430 const result_type
& operator()() const { return _M_val
; }
433 template <class _Result
, class _Argument
>
434 struct _Constant_unary_fun
{
435 typedef _Argument argument_type
;
436 typedef _Result result_type
;
439 _Constant_unary_fun(const result_type
& __v
) : _M_val(__v
) {}
440 const result_type
& operator()(const _Argument
&) const { return _M_val
; }
443 template <class _Result
, class _Arg1
, class _Arg2
>
444 struct _Constant_binary_fun
{
445 typedef _Arg1 first_argument_type
;
446 typedef _Arg2 second_argument_type
;
447 typedef _Result result_type
;
450 _Constant_binary_fun(const _Result
& __v
) : _M_val(__v
) {}
451 const result_type
& operator()(const _Arg1
&, const _Arg2
&) const {
456 template <class _Result
>
457 struct constant_void_fun
: public _Constant_void_fun
<_Result
> {
458 constant_void_fun(const _Result
& __v
) : _Constant_void_fun
<_Result
>(__v
) {}
462 template <class _Result
,
463 class _Argument
= _Result
>
464 struct constant_unary_fun
: public _Constant_unary_fun
<_Result
, _Argument
>
466 constant_unary_fun(const _Result
& __v
)
467 : _Constant_unary_fun
<_Result
, _Argument
>(__v
) {}
471 template <class _Result
,
472 class _Arg1
= _Result
,
474 struct constant_binary_fun
475 : public _Constant_binary_fun
<_Result
, _Arg1
, _Arg2
>
477 constant_binary_fun(const _Result
& __v
)
478 : _Constant_binary_fun
<_Result
, _Arg1
, _Arg2
>(__v
) {}
481 template <class _Result
>
482 inline constant_void_fun
<_Result
> constant0(const _Result
& __val
)
484 return constant_void_fun
<_Result
>(__val
);
487 template <class _Result
>
488 inline constant_unary_fun
<_Result
,_Result
> constant1(const _Result
& __val
)
490 return constant_unary_fun
<_Result
,_Result
>(__val
);
493 template <class _Result
>
494 inline constant_binary_fun
<_Result
,_Result
,_Result
>
495 constant2(const _Result
& __val
)
497 return constant_binary_fun
<_Result
,_Result
,_Result
>(__val
);
500 // subtractive_rng is an extension: it is not part of the standard.
501 // Note: this code assumes that int is 32 bits.
502 class subtractive_rng
: public unary_function
<unsigned int, unsigned int> {
504 unsigned int _M_table
[55];
508 unsigned int operator()(unsigned int __limit
) {
509 _M_index1
= (_M_index1
+ 1) % 55;
510 _M_index2
= (_M_index2
+ 1) % 55;
511 _M_table
[_M_index1
] = _M_table
[_M_index1
] - _M_table
[_M_index2
];
512 return _M_table
[_M_index1
] % __limit
;
515 void _M_initialize(unsigned int __seed
)
517 unsigned int __k
= 1;
518 _M_table
[54] = __seed
;
520 for (__i
= 0; __i
< 54; __i
++) {
521 size_t __ii
= (21 * (__i
+ 1) % 55) - 1;
522 _M_table
[__ii
] = __k
;
524 __seed
= _M_table
[__ii
];
526 for (int __loop
= 0; __loop
< 4; __loop
++) {
527 for (__i
= 0; __i
< 55; __i
++)
528 _M_table
[__i
] = _M_table
[__i
] - _M_table
[(1 + __i
+ 30) % 55];
534 subtractive_rng(unsigned int __seed
) { _M_initialize(__seed
); }
535 subtractive_rng() { _M_initialize(161803398u); }
539 // Adaptor function objects: pointers to member functions.
541 // There are a total of 16 = 2^4 function objects in this family.
542 // (1) Member functions taking no arguments vs member functions taking
544 // (2) Call through pointer vs call through reference.
545 // (3) Member function with void return type vs member function with
546 // non-void return type.
547 // (4) Const vs non-const member function.
549 // Note that choice (3) is nothing more than a workaround: according
550 // to the draft, compilers should handle void and non-void the same way.
551 // This feature is not yet widely implemented, though. You can only use
552 // member functions returning void if your compiler supports partial
555 // All of this complexity is in the function objects themselves. You can
556 // ignore it by using the helper function mem_fun and mem_fun_ref,
557 // which create whichever type of adaptor is appropriate.
558 // (mem_fun1 and mem_fun1_ref are no longer part of the C++ standard,
559 // but they are provided for backward compatibility.)
562 template <class _Ret
, class _Tp
>
563 class mem_fun_t
: public unary_function
<_Tp
*,_Ret
> {
565 explicit mem_fun_t(_Ret (_Tp::*__pf
)()) : _M_f(__pf
) {}
566 _Ret
operator()(_Tp
* __p
) const { return (__p
->*_M_f
)(); }
571 template <class _Ret
, class _Tp
>
572 class const_mem_fun_t
: public unary_function
<const _Tp
*,_Ret
> {
574 explicit const_mem_fun_t(_Ret (_Tp::*__pf
)() const) : _M_f(__pf
) {}
575 _Ret
operator()(const _Tp
* __p
) const { return (__p
->*_M_f
)(); }
577 _Ret (_Tp::*_M_f
)() const;
581 template <class _Ret
, class _Tp
>
582 class mem_fun_ref_t
: public unary_function
<_Tp
,_Ret
> {
584 explicit mem_fun_ref_t(_Ret (_Tp::*__pf
)()) : _M_f(__pf
) {}
585 _Ret
operator()(_Tp
& __r
) const { return (__r
.*_M_f
)(); }
590 template <class _Ret
, class _Tp
>
591 class const_mem_fun_ref_t
: public unary_function
<_Tp
,_Ret
> {
593 explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf
)() const) : _M_f(__pf
) {}
594 _Ret
operator()(const _Tp
& __r
) const { return (__r
.*_M_f
)(); }
596 _Ret (_Tp::*_M_f
)() const;
599 template <class _Ret
, class _Tp
, class _Arg
>
600 class mem_fun1_t
: public binary_function
<_Tp
*,_Arg
,_Ret
> {
602 explicit mem_fun1_t(_Ret (_Tp::*__pf
)(_Arg
)) : _M_f(__pf
) {}
603 _Ret
operator()(_Tp
* __p
, _Arg __x
) const { return (__p
->*_M_f
)(__x
); }
605 _Ret (_Tp::*_M_f
)(_Arg
);
608 template <class _Ret
, class _Tp
, class _Arg
>
609 class const_mem_fun1_t
: public binary_function
<const _Tp
*,_Arg
,_Ret
> {
611 explicit const_mem_fun1_t(_Ret (_Tp::*__pf
)(_Arg
) const) : _M_f(__pf
) {}
612 _Ret
operator()(const _Tp
* __p
, _Arg __x
) const
613 { return (__p
->*_M_f
)(__x
); }
615 _Ret (_Tp::*_M_f
)(_Arg
) const;
618 template <class _Ret
, class _Tp
, class _Arg
>
619 class mem_fun1_ref_t
: public binary_function
<_Tp
,_Arg
,_Ret
> {
621 explicit mem_fun1_ref_t(_Ret (_Tp::*__pf
)(_Arg
)) : _M_f(__pf
) {}
622 _Ret
operator()(_Tp
& __r
, _Arg __x
) const { return (__r
.*_M_f
)(__x
); }
624 _Ret (_Tp::*_M_f
)(_Arg
);
627 template <class _Ret
, class _Tp
, class _Arg
>
628 class const_mem_fun1_ref_t
: public binary_function
<_Tp
,_Arg
,_Ret
> {
630 explicit const_mem_fun1_ref_t(_Ret (_Tp::*__pf
)(_Arg
) const) : _M_f(__pf
) {}
631 _Ret
operator()(const _Tp
& __r
, _Arg __x
) const { return (__r
.*_M_f
)(__x
); }
633 _Ret (_Tp::*_M_f
)(_Arg
) const;
637 class mem_fun_t
<void, _Tp
> : public unary_function
<_Tp
*,void> {
639 explicit mem_fun_t(void (_Tp::*__pf
)()) : _M_f(__pf
) {}
640 void operator()(_Tp
* __p
) const { (__p
->*_M_f
)(); }
646 class const_mem_fun_t
<void, _Tp
> : public unary_function
<const _Tp
*,void> {
648 explicit const_mem_fun_t(void (_Tp::*__pf
)() const) : _M_f(__pf
) {}
649 void operator()(const _Tp
* __p
) const { (__p
->*_M_f
)(); }
651 void (_Tp::*_M_f
)() const;
655 class mem_fun_ref_t
<void, _Tp
> : public unary_function
<_Tp
,void> {
657 explicit mem_fun_ref_t(void (_Tp::*__pf
)()) : _M_f(__pf
) {}
658 void operator()(_Tp
& __r
) const { (__r
.*_M_f
)(); }
664 class const_mem_fun_ref_t
<void, _Tp
> : public unary_function
<_Tp
,void> {
666 explicit const_mem_fun_ref_t(void (_Tp::*__pf
)() const) : _M_f(__pf
) {}
667 void operator()(const _Tp
& __r
) const { (__r
.*_M_f
)(); }
669 void (_Tp::*_M_f
)() const;
672 template <class _Tp
, class _Arg
>
673 class mem_fun1_t
<void, _Tp
, _Arg
> : public binary_function
<_Tp
*,_Arg
,void> {
675 explicit mem_fun1_t(void (_Tp::*__pf
)(_Arg
)) : _M_f(__pf
) {}
676 void operator()(_Tp
* __p
, _Arg __x
) const { (__p
->*_M_f
)(__x
); }
678 void (_Tp::*_M_f
)(_Arg
);
681 template <class _Tp
, class _Arg
>
682 class const_mem_fun1_t
<void, _Tp
, _Arg
>
683 : public binary_function
<const _Tp
*,_Arg
,void> {
685 explicit const_mem_fun1_t(void (_Tp::*__pf
)(_Arg
) const) : _M_f(__pf
) {}
686 void operator()(const _Tp
* __p
, _Arg __x
) const { (__p
->*_M_f
)(__x
); }
688 void (_Tp::*_M_f
)(_Arg
) const;
691 template <class _Tp
, class _Arg
>
692 class mem_fun1_ref_t
<void, _Tp
, _Arg
>
693 : public binary_function
<_Tp
,_Arg
,void> {
695 explicit mem_fun1_ref_t(void (_Tp::*__pf
)(_Arg
)) : _M_f(__pf
) {}
696 void operator()(_Tp
& __r
, _Arg __x
) const { (__r
.*_M_f
)(__x
); }
698 void (_Tp::*_M_f
)(_Arg
);
701 template <class _Tp
, class _Arg
>
702 class const_mem_fun1_ref_t
<void, _Tp
, _Arg
>
703 : public binary_function
<_Tp
,_Arg
,void> {
705 explicit const_mem_fun1_ref_t(void (_Tp::*__pf
)(_Arg
) const) : _M_f(__pf
) {}
706 void operator()(const _Tp
& __r
, _Arg __x
) const { (__r
.*_M_f
)(__x
); }
708 void (_Tp::*_M_f
)(_Arg
) const;
712 // Mem_fun adaptor helper functions. There are only two:
713 // mem_fun and mem_fun_ref. (mem_fun1 and mem_fun1_ref
714 // are provided for backward compatibility, but they are no longer
715 // part of the C++ standard.)
717 template <class _Ret
, class _Tp
>
718 inline mem_fun_t
<_Ret
,_Tp
> mem_fun(_Ret (_Tp::*__f
)())
719 { return mem_fun_t
<_Ret
,_Tp
>(__f
); }
721 template <class _Ret
, class _Tp
>
722 inline const_mem_fun_t
<_Ret
,_Tp
> mem_fun(_Ret (_Tp::*__f
)() const)
723 { return const_mem_fun_t
<_Ret
,_Tp
>(__f
); }
725 template <class _Ret
, class _Tp
>
726 inline mem_fun_ref_t
<_Ret
,_Tp
> mem_fun_ref(_Ret (_Tp::*__f
)())
727 { return mem_fun_ref_t
<_Ret
,_Tp
>(__f
); }
729 template <class _Ret
, class _Tp
>
730 inline const_mem_fun_ref_t
<_Ret
,_Tp
> mem_fun_ref(_Ret (_Tp::*__f
)() const)
731 { return const_mem_fun_ref_t
<_Ret
,_Tp
>(__f
); }
733 template <class _Ret
, class _Tp
, class _Arg
>
734 inline mem_fun1_t
<_Ret
,_Tp
,_Arg
> mem_fun(_Ret (_Tp::*__f
)(_Arg
))
735 { return mem_fun1_t
<_Ret
,_Tp
,_Arg
>(__f
); }
737 template <class _Ret
, class _Tp
, class _Arg
>
738 inline const_mem_fun1_t
<_Ret
,_Tp
,_Arg
> mem_fun(_Ret (_Tp::*__f
)(_Arg
) const)
739 { return const_mem_fun1_t
<_Ret
,_Tp
,_Arg
>(__f
); }
741 template <class _Ret
, class _Tp
, class _Arg
>
742 inline mem_fun1_ref_t
<_Ret
,_Tp
,_Arg
> mem_fun_ref(_Ret (_Tp::*__f
)(_Arg
))
743 { return mem_fun1_ref_t
<_Ret
,_Tp
,_Arg
>(__f
); }
745 template <class _Ret
, class _Tp
, class _Arg
>
746 inline const_mem_fun1_ref_t
<_Ret
,_Tp
,_Arg
>
747 mem_fun_ref(_Ret (_Tp::*__f
)(_Arg
) const)
748 { return const_mem_fun1_ref_t
<_Ret
,_Tp
,_Arg
>(__f
); }
750 template <class _Ret
, class _Tp
, class _Arg
>
751 inline mem_fun1_t
<_Ret
,_Tp
,_Arg
> mem_fun1(_Ret (_Tp::*__f
)(_Arg
))
752 { return mem_fun1_t
<_Ret
,_Tp
,_Arg
>(__f
); }
754 template <class _Ret
, class _Tp
, class _Arg
>
755 inline const_mem_fun1_t
<_Ret
,_Tp
,_Arg
> mem_fun1(_Ret (_Tp::*__f
)(_Arg
) const)
756 { return const_mem_fun1_t
<_Ret
,_Tp
,_Arg
>(__f
); }
758 template <class _Ret
, class _Tp
, class _Arg
>
759 inline mem_fun1_ref_t
<_Ret
,_Tp
,_Arg
> mem_fun1_ref(_Ret (_Tp::*__f
)(_Arg
))
760 { return mem_fun1_ref_t
<_Ret
,_Tp
,_Arg
>(__f
); }
762 template <class _Ret
, class _Tp
, class _Arg
>
763 inline const_mem_fun1_ref_t
<_Ret
,_Tp
,_Arg
>
764 mem_fun1_ref(_Ret (_Tp::*__f
)(_Arg
) const)
765 { return const_mem_fun1_ref_t
<_Ret
,_Tp
,_Arg
>(__f
); }
769 #endif /* __SGI_STL_INTERNAL_FUNCTION_H */