algo.h: Add "GPL plus runtime exception" comment block, this time for real.
[gcc.git] / libstdc++-v3 / include / bits / stl_function.h
1 // Functor implementations -*- C++ -*-
2
3 // Copyright (C) 2001 Free Software Foundation, Inc.
4 //
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)
9 // any later version.
10
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.
15
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,
19 // USA.
20
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.
29
30 /*
31 *
32 * Copyright (c) 1994
33 * Hewlett-Packard Company
34 *
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.
42 *
43 *
44 * Copyright (c) 1996-1998
45 * Silicon Graphics Computer Systems, Inc.
46 *
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.
54 */
55
56 /* NOTE: This is an internal header file, included by other STL headers.
57 * You should not attempt to use it directly.
58 */
59
60 #ifndef __SGI_STL_INTERNAL_FUNCTION_H
61 #define __SGI_STL_INTERNAL_FUNCTION_H
62
63 namespace std
64 {
65
66 template <class _Arg, class _Result>
67 struct unary_function {
68 typedef _Arg argument_type;
69 typedef _Result result_type;
70 };
71
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;
77 };
78
79 template <class _Tp>
80 struct plus : public binary_function<_Tp,_Tp,_Tp> {
81 _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x + __y; }
82 };
83
84 template <class _Tp>
85 struct minus : public binary_function<_Tp,_Tp,_Tp> {
86 _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x - __y; }
87 };
88
89 template <class _Tp>
90 struct multiplies : public binary_function<_Tp,_Tp,_Tp> {
91 _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x * __y; }
92 };
93
94 template <class _Tp>
95 struct divides : public binary_function<_Tp,_Tp,_Tp> {
96 _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x / __y; }
97 };
98
99 // identity_element (not part of the C++ standard).
100
101 template <class _Tp> inline _Tp identity_element(plus<_Tp>) {
102 return _Tp(0);
103 }
104 template <class _Tp> inline _Tp identity_element(multiplies<_Tp>) {
105 return _Tp(1);
106 }
107
108 template <class _Tp>
109 struct modulus : public binary_function<_Tp,_Tp,_Tp>
110 {
111 _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x % __y; }
112 };
113
114 template <class _Tp>
115 struct negate : public unary_function<_Tp,_Tp>
116 {
117 _Tp operator()(const _Tp& __x) const { return -__x; }
118 };
119
120 template <class _Tp>
121 struct equal_to : public binary_function<_Tp,_Tp,bool>
122 {
123 bool operator()(const _Tp& __x, const _Tp& __y) const { return __x == __y; }
124 };
125
126 template <class _Tp>
127 struct not_equal_to : public binary_function<_Tp,_Tp,bool>
128 {
129 bool operator()(const _Tp& __x, const _Tp& __y) const { return __x != __y; }
130 };
131
132 template <class _Tp>
133 struct greater : public binary_function<_Tp,_Tp,bool>
134 {
135 bool operator()(const _Tp& __x, const _Tp& __y) const { return __x > __y; }
136 };
137
138 template <class _Tp>
139 struct less : public binary_function<_Tp,_Tp,bool>
140 {
141 bool operator()(const _Tp& __x, const _Tp& __y) const { return __x < __y; }
142 };
143
144 template <class _Tp>
145 struct greater_equal : public binary_function<_Tp,_Tp,bool>
146 {
147 bool operator()(const _Tp& __x, const _Tp& __y) const { return __x >= __y; }
148 };
149
150 template <class _Tp>
151 struct less_equal : public binary_function<_Tp,_Tp,bool>
152 {
153 bool operator()(const _Tp& __x, const _Tp& __y) const { return __x <= __y; }
154 };
155
156 template <class _Tp>
157 struct logical_and : public binary_function<_Tp,_Tp,bool>
158 {
159 bool operator()(const _Tp& __x, const _Tp& __y) const { return __x && __y; }
160 };
161
162 template <class _Tp>
163 struct logical_or : public binary_function<_Tp,_Tp,bool>
164 {
165 bool operator()(const _Tp& __x, const _Tp& __y) const { return __x || __y; }
166 };
167
168 template <class _Tp>
169 struct logical_not : public unary_function<_Tp,bool>
170 {
171 bool operator()(const _Tp& __x) const { return !__x; }
172 };
173
174 template <class _Predicate>
175 class unary_negate
176 : public unary_function<typename _Predicate::argument_type, bool> {
177 protected:
178 _Predicate _M_pred;
179 public:
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);
183 }
184 };
185
186 template <class _Predicate>
187 inline unary_negate<_Predicate>
188 not1(const _Predicate& __pred)
189 {
190 return unary_negate<_Predicate>(__pred);
191 }
192
193 template <class _Predicate>
194 class binary_negate
195 : public binary_function<typename _Predicate::first_argument_type,
196 typename _Predicate::second_argument_type,
197 bool> {
198 protected:
199 _Predicate _M_pred;
200 public:
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
204 {
205 return !_M_pred(__x, __y);
206 }
207 };
208
209 template <class _Predicate>
210 inline binary_negate<_Predicate>
211 not2(const _Predicate& __pred)
212 {
213 return binary_negate<_Predicate>(__pred);
214 }
215
216 template <class _Operation>
217 class binder1st
218 : public unary_function<typename _Operation::second_argument_type,
219 typename _Operation::result_type> {
220 protected:
221 _Operation op;
222 typename _Operation::first_argument_type value;
223 public:
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);
230 }
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);
236 }
237 #endif
238 };
239
240 template <class _Operation, class _Tp>
241 inline binder1st<_Operation>
242 bind1st(const _Operation& __fn, const _Tp& __x)
243 {
244 typedef typename _Operation::first_argument_type _Arg1_type;
245 return binder1st<_Operation>(__fn, _Arg1_type(__x));
246 }
247
248 template <class _Operation>
249 class binder2nd
250 : public unary_function<typename _Operation::first_argument_type,
251 typename _Operation::result_type> {
252 protected:
253 _Operation op;
254 typename _Operation::second_argument_type value;
255 public:
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);
262 }
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);
268 }
269 #endif
270 };
271
272 template <class _Operation, class _Tp>
273 inline binder2nd<_Operation>
274 bind2nd(const _Operation& __fn, const _Tp& __x)
275 {
276 typedef typename _Operation::second_argument_type _Arg2_type;
277 return binder2nd<_Operation>(__fn, _Arg2_type(__x));
278 }
279
280 // unary_compose and binary_compose (extensions, not part of the standard).
281
282 template <class _Operation1, class _Operation2>
283 class unary_compose
284 : public unary_function<typename _Operation2::argument_type,
285 typename _Operation1::result_type>
286 {
287 protected:
288 _Operation1 _M_fn1;
289 _Operation2 _M_fn2;
290 public:
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));
296 }
297 };
298
299 template <class _Operation1, class _Operation2>
300 inline unary_compose<_Operation1,_Operation2>
301 compose1(const _Operation1& __fn1, const _Operation2& __fn2)
302 {
303 return unary_compose<_Operation1,_Operation2>(__fn1, __fn2);
304 }
305
306 template <class _Operation1, class _Operation2, class _Operation3>
307 class binary_compose
308 : public unary_function<typename _Operation2::argument_type,
309 typename _Operation1::result_type> {
310 protected:
311 _Operation1 _M_fn1;
312 _Operation2 _M_fn2;
313 _Operation3 _M_fn3;
314 public:
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));
321 }
322 };
323
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)
328 {
329 return binary_compose<_Operation1,_Operation2,_Operation3>
330 (__fn1, __fn2, __fn3);
331 }
332
333 template <class _Arg, class _Result>
334 class pointer_to_unary_function : public unary_function<_Arg, _Result> {
335 protected:
336 _Result (*_M_ptr)(_Arg);
337 public:
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); }
341 };
342
343 template <class _Arg, class _Result>
344 inline pointer_to_unary_function<_Arg, _Result> ptr_fun(_Result (*__x)(_Arg))
345 {
346 return pointer_to_unary_function<_Arg, _Result>(__x);
347 }
348
349 template <class _Arg1, class _Arg2, class _Result>
350 class pointer_to_binary_function :
351 public binary_function<_Arg1,_Arg2,_Result> {
352 protected:
353 _Result (*_M_ptr)(_Arg1, _Arg2);
354 public:
355 pointer_to_binary_function() {}
356 explicit pointer_to_binary_function(_Result (*__x)(_Arg1, _Arg2))
357 : _M_ptr(__x) {}
358 _Result operator()(_Arg1 __x, _Arg2 __y) const {
359 return _M_ptr(__x, __y);
360 }
361 };
362
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);
367 }
368
369 // identity is an extensions: it is not part of the standard.
370 template <class _Tp>
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; }
374 };
375
376 template <class _Tp> struct identity : public _Identity<_Tp> {};
377
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 {
382 return __x.first;
383 }
384 const typename _Pair::first_type& operator()(const _Pair& __x) const {
385 return __x.first;
386 }
387 };
388
389 template <class _Pair>
390 struct _Select2nd : public unary_function<_Pair, typename _Pair::second_type>
391 {
392 typename _Pair::second_type& operator()(_Pair& __x) const {
393 return __x.second;
394 }
395 const typename _Pair::second_type& operator()(const _Pair& __x) const {
396 return __x.second;
397 }
398 };
399
400 template <class _Pair> struct select1st : public _Select1st<_Pair> {};
401 template <class _Pair> struct select2nd : public _Select2nd<_Pair> {};
402
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; }
407 };
408
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; }
412 };
413
414 template <class _Arg1, class _Arg2>
415 struct project1st : public _Project1st<_Arg1, _Arg2> {};
416
417 template <class _Arg1, class _Arg2>
418 struct project2nd : public _Project2nd<_Arg1, _Arg2> {};
419
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.)
423
424 template <class _Result>
425 struct _Constant_void_fun {
426 typedef _Result result_type;
427 result_type _M_val;
428
429 _Constant_void_fun(const result_type& __v) : _M_val(__v) {}
430 const result_type& operator()() const { return _M_val; }
431 };
432
433 template <class _Result, class _Argument>
434 struct _Constant_unary_fun {
435 typedef _Argument argument_type;
436 typedef _Result result_type;
437 result_type _M_val;
438
439 _Constant_unary_fun(const result_type& __v) : _M_val(__v) {}
440 const result_type& operator()(const _Argument&) const { return _M_val; }
441 };
442
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;
448 _Result _M_val;
449
450 _Constant_binary_fun(const _Result& __v) : _M_val(__v) {}
451 const result_type& operator()(const _Arg1&, const _Arg2&) const {
452 return _M_val;
453 }
454 };
455
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) {}
459 };
460
461
462 template <class _Result,
463 class _Argument = _Result>
464 struct constant_unary_fun : public _Constant_unary_fun<_Result, _Argument>
465 {
466 constant_unary_fun(const _Result& __v)
467 : _Constant_unary_fun<_Result, _Argument>(__v) {}
468 };
469
470
471 template <class _Result,
472 class _Arg1 = _Result,
473 class _Arg2 = _Arg1>
474 struct constant_binary_fun
475 : public _Constant_binary_fun<_Result, _Arg1, _Arg2>
476 {
477 constant_binary_fun(const _Result& __v)
478 : _Constant_binary_fun<_Result, _Arg1, _Arg2>(__v) {}
479 };
480
481 template <class _Result>
482 inline constant_void_fun<_Result> constant0(const _Result& __val)
483 {
484 return constant_void_fun<_Result>(__val);
485 }
486
487 template <class _Result>
488 inline constant_unary_fun<_Result,_Result> constant1(const _Result& __val)
489 {
490 return constant_unary_fun<_Result,_Result>(__val);
491 }
492
493 template <class _Result>
494 inline constant_binary_fun<_Result,_Result,_Result>
495 constant2(const _Result& __val)
496 {
497 return constant_binary_fun<_Result,_Result,_Result>(__val);
498 }
499
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> {
503 private:
504 unsigned int _M_table[55];
505 size_t _M_index1;
506 size_t _M_index2;
507 public:
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;
513 }
514
515 void _M_initialize(unsigned int __seed)
516 {
517 unsigned int __k = 1;
518 _M_table[54] = __seed;
519 size_t __i;
520 for (__i = 0; __i < 54; __i++) {
521 size_t __ii = (21 * (__i + 1) % 55) - 1;
522 _M_table[__ii] = __k;
523 __k = __seed - __k;
524 __seed = _M_table[__ii];
525 }
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];
529 }
530 _M_index1 = 0;
531 _M_index2 = 31;
532 }
533
534 subtractive_rng(unsigned int __seed) { _M_initialize(__seed); }
535 subtractive_rng() { _M_initialize(161803398u); }
536 };
537
538
539 // Adaptor function objects: pointers to member functions.
540
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
543 // one argument.
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.
548
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
553 // specialization.
554
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.)
560
561
562 template <class _Ret, class _Tp>
563 class mem_fun_t : public unary_function<_Tp*,_Ret> {
564 public:
565 explicit mem_fun_t(_Ret (_Tp::*__pf)()) : _M_f(__pf) {}
566 _Ret operator()(_Tp* __p) const { return (__p->*_M_f)(); }
567 private:
568 _Ret (_Tp::*_M_f)();
569 };
570
571 template <class _Ret, class _Tp>
572 class const_mem_fun_t : public unary_function<const _Tp*,_Ret> {
573 public:
574 explicit const_mem_fun_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}
575 _Ret operator()(const _Tp* __p) const { return (__p->*_M_f)(); }
576 private:
577 _Ret (_Tp::*_M_f)() const;
578 };
579
580
581 template <class _Ret, class _Tp>
582 class mem_fun_ref_t : public unary_function<_Tp,_Ret> {
583 public:
584 explicit mem_fun_ref_t(_Ret (_Tp::*__pf)()) : _M_f(__pf) {}
585 _Ret operator()(_Tp& __r) const { return (__r.*_M_f)(); }
586 private:
587 _Ret (_Tp::*_M_f)();
588 };
589
590 template <class _Ret, class _Tp>
591 class const_mem_fun_ref_t : public unary_function<_Tp,_Ret> {
592 public:
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)(); }
595 private:
596 _Ret (_Tp::*_M_f)() const;
597 };
598
599 template <class _Ret, class _Tp, class _Arg>
600 class mem_fun1_t : public binary_function<_Tp*,_Arg,_Ret> {
601 public:
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); }
604 private:
605 _Ret (_Tp::*_M_f)(_Arg);
606 };
607
608 template <class _Ret, class _Tp, class _Arg>
609 class const_mem_fun1_t : public binary_function<const _Tp*,_Arg,_Ret> {
610 public:
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); }
614 private:
615 _Ret (_Tp::*_M_f)(_Arg) const;
616 };
617
618 template <class _Ret, class _Tp, class _Arg>
619 class mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> {
620 public:
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); }
623 private:
624 _Ret (_Tp::*_M_f)(_Arg);
625 };
626
627 template <class _Ret, class _Tp, class _Arg>
628 class const_mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> {
629 public:
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); }
632 private:
633 _Ret (_Tp::*_M_f)(_Arg) const;
634 };
635
636 template <class _Tp>
637 class mem_fun_t<void, _Tp> : public unary_function<_Tp*,void> {
638 public:
639 explicit mem_fun_t(void (_Tp::*__pf)()) : _M_f(__pf) {}
640 void operator()(_Tp* __p) const { (__p->*_M_f)(); }
641 private:
642 void (_Tp::*_M_f)();
643 };
644
645 template <class _Tp>
646 class const_mem_fun_t<void, _Tp> : public unary_function<const _Tp*,void> {
647 public:
648 explicit const_mem_fun_t(void (_Tp::*__pf)() const) : _M_f(__pf) {}
649 void operator()(const _Tp* __p) const { (__p->*_M_f)(); }
650 private:
651 void (_Tp::*_M_f)() const;
652 };
653
654 template <class _Tp>
655 class mem_fun_ref_t<void, _Tp> : public unary_function<_Tp,void> {
656 public:
657 explicit mem_fun_ref_t(void (_Tp::*__pf)()) : _M_f(__pf) {}
658 void operator()(_Tp& __r) const { (__r.*_M_f)(); }
659 private:
660 void (_Tp::*_M_f)();
661 };
662
663 template <class _Tp>
664 class const_mem_fun_ref_t<void, _Tp> : public unary_function<_Tp,void> {
665 public:
666 explicit const_mem_fun_ref_t(void (_Tp::*__pf)() const) : _M_f(__pf) {}
667 void operator()(const _Tp& __r) const { (__r.*_M_f)(); }
668 private:
669 void (_Tp::*_M_f)() const;
670 };
671
672 template <class _Tp, class _Arg>
673 class mem_fun1_t<void, _Tp, _Arg> : public binary_function<_Tp*,_Arg,void> {
674 public:
675 explicit mem_fun1_t(void (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}
676 void operator()(_Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }
677 private:
678 void (_Tp::*_M_f)(_Arg);
679 };
680
681 template <class _Tp, class _Arg>
682 class const_mem_fun1_t<void, _Tp, _Arg>
683 : public binary_function<const _Tp*,_Arg,void> {
684 public:
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); }
687 private:
688 void (_Tp::*_M_f)(_Arg) const;
689 };
690
691 template <class _Tp, class _Arg>
692 class mem_fun1_ref_t<void, _Tp, _Arg>
693 : public binary_function<_Tp,_Arg,void> {
694 public:
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); }
697 private:
698 void (_Tp::*_M_f)(_Arg);
699 };
700
701 template <class _Tp, class _Arg>
702 class const_mem_fun1_ref_t<void, _Tp, _Arg>
703 : public binary_function<_Tp,_Arg,void> {
704 public:
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); }
707 private:
708 void (_Tp::*_M_f)(_Arg) const;
709 };
710
711
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.)
716
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); }
720
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); }
724
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); }
728
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); }
732
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); }
736
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); }
740
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); }
744
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); }
749
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); }
753
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); }
757
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); }
761
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); }
766
767 } // namespace std
768
769 #endif /* __SGI_STL_INTERNAL_FUNCTION_H */
770
771 // Local Variables:
772 // mode:C++
773 // End: