algo.h: Use std not __STD.
[gcc.git] / libstdc++-v3 / include / bits / stl_function.h
1 /*
2 *
3 * Copyright (c) 1994
4 * Hewlett-Packard Company
5 *
6 * Permission to use, copy, modify, distribute and sell this software
7 * and its documentation for any purpose is hereby granted without fee,
8 * provided that the above copyright notice appear in all copies and
9 * that both that copyright notice and this permission notice appear
10 * in supporting documentation. Hewlett-Packard Company makes no
11 * representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
13 *
14 *
15 * Copyright (c) 1996-1998
16 * Silicon Graphics Computer Systems, Inc.
17 *
18 * Permission to use, copy, modify, distribute and sell this software
19 * and its documentation for any purpose is hereby granted without fee,
20 * provided that the above copyright notice appear in all copies and
21 * that both that copyright notice and this permission notice appear
22 * in supporting documentation. Silicon Graphics makes no
23 * representations about the suitability of this software for any
24 * purpose. It is provided "as is" without express or implied warranty.
25 */
26
27 /* NOTE: This is an internal header file, included by other STL headers.
28 * You should not attempt to use it directly.
29 */
30
31 #ifndef __SGI_STL_INTERNAL_FUNCTION_H
32 #define __SGI_STL_INTERNAL_FUNCTION_H
33
34 namespace std
35 {
36
37 template <class _Arg, class _Result>
38 struct unary_function {
39 typedef _Arg argument_type;
40 typedef _Result result_type;
41 };
42
43 template <class _Arg1, class _Arg2, class _Result>
44 struct binary_function {
45 typedef _Arg1 first_argument_type;
46 typedef _Arg2 second_argument_type;
47 typedef _Result result_type;
48 };
49
50 template <class _Tp>
51 struct plus : public binary_function<_Tp,_Tp,_Tp> {
52 _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x + __y; }
53 };
54
55 template <class _Tp>
56 struct minus : public binary_function<_Tp,_Tp,_Tp> {
57 _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x - __y; }
58 };
59
60 template <class _Tp>
61 struct multiplies : public binary_function<_Tp,_Tp,_Tp> {
62 _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x * __y; }
63 };
64
65 template <class _Tp>
66 struct divides : public binary_function<_Tp,_Tp,_Tp> {
67 _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x / __y; }
68 };
69
70 // identity_element (not part of the C++ standard).
71
72 template <class _Tp> inline _Tp identity_element(plus<_Tp>) {
73 return _Tp(0);
74 }
75 template <class _Tp> inline _Tp identity_element(multiplies<_Tp>) {
76 return _Tp(1);
77 }
78
79 template <class _Tp>
80 struct modulus : public binary_function<_Tp,_Tp,_Tp>
81 {
82 _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x % __y; }
83 };
84
85 template <class _Tp>
86 struct negate : public unary_function<_Tp,_Tp>
87 {
88 _Tp operator()(const _Tp& __x) const { return -__x; }
89 };
90
91 template <class _Tp>
92 struct equal_to : public binary_function<_Tp,_Tp,bool>
93 {
94 bool operator()(const _Tp& __x, const _Tp& __y) const { return __x == __y; }
95 };
96
97 template <class _Tp>
98 struct not_equal_to : public binary_function<_Tp,_Tp,bool>
99 {
100 bool operator()(const _Tp& __x, const _Tp& __y) const { return __x != __y; }
101 };
102
103 template <class _Tp>
104 struct greater : public binary_function<_Tp,_Tp,bool>
105 {
106 bool operator()(const _Tp& __x, const _Tp& __y) const { return __x > __y; }
107 };
108
109 template <class _Tp>
110 struct less : public binary_function<_Tp,_Tp,bool>
111 {
112 bool operator()(const _Tp& __x, const _Tp& __y) const { return __x < __y; }
113 };
114
115 template <class _Tp>
116 struct greater_equal : public binary_function<_Tp,_Tp,bool>
117 {
118 bool operator()(const _Tp& __x, const _Tp& __y) const { return __x >= __y; }
119 };
120
121 template <class _Tp>
122 struct less_equal : public binary_function<_Tp,_Tp,bool>
123 {
124 bool operator()(const _Tp& __x, const _Tp& __y) const { return __x <= __y; }
125 };
126
127 template <class _Tp>
128 struct logical_and : public binary_function<_Tp,_Tp,bool>
129 {
130 bool operator()(const _Tp& __x, const _Tp& __y) const { return __x && __y; }
131 };
132
133 template <class _Tp>
134 struct logical_or : public binary_function<_Tp,_Tp,bool>
135 {
136 bool operator()(const _Tp& __x, const _Tp& __y) const { return __x || __y; }
137 };
138
139 template <class _Tp>
140 struct logical_not : public unary_function<_Tp,bool>
141 {
142 bool operator()(const _Tp& __x) const { return !__x; }
143 };
144
145 template <class _Predicate>
146 class unary_negate
147 : public unary_function<typename _Predicate::argument_type, bool> {
148 protected:
149 _Predicate _M_pred;
150 public:
151 explicit unary_negate(const _Predicate& __x) : _M_pred(__x) {}
152 bool operator()(const typename _Predicate::argument_type& __x) const {
153 return !_M_pred(__x);
154 }
155 };
156
157 template <class _Predicate>
158 inline unary_negate<_Predicate>
159 not1(const _Predicate& __pred)
160 {
161 return unary_negate<_Predicate>(__pred);
162 }
163
164 template <class _Predicate>
165 class binary_negate
166 : public binary_function<typename _Predicate::first_argument_type,
167 typename _Predicate::second_argument_type,
168 bool> {
169 protected:
170 _Predicate _M_pred;
171 public:
172 explicit binary_negate(const _Predicate& __x) : _M_pred(__x) {}
173 bool operator()(const typename _Predicate::first_argument_type& __x,
174 const typename _Predicate::second_argument_type& __y) const
175 {
176 return !_M_pred(__x, __y);
177 }
178 };
179
180 template <class _Predicate>
181 inline binary_negate<_Predicate>
182 not2(const _Predicate& __pred)
183 {
184 return binary_negate<_Predicate>(__pred);
185 }
186
187 template <class _Operation>
188 class binder1st
189 : public unary_function<typename _Operation::second_argument_type,
190 typename _Operation::result_type> {
191 protected:
192 _Operation op;
193 typename _Operation::first_argument_type value;
194 public:
195 binder1st(const _Operation& __x,
196 const typename _Operation::first_argument_type& __y)
197 : op(__x), value(__y) {}
198 typename _Operation::result_type
199 operator()(const typename _Operation::second_argument_type& __x) const {
200 return op(value, __x);
201 }
202 };
203
204 template <class _Operation, class _Tp>
205 inline binder1st<_Operation>
206 bind1st(const _Operation& __fn, const _Tp& __x)
207 {
208 typedef typename _Operation::first_argument_type _Arg1_type;
209 return binder1st<_Operation>(__fn, _Arg1_type(__x));
210 }
211
212 template <class _Operation>
213 class binder2nd
214 : public unary_function<typename _Operation::first_argument_type,
215 typename _Operation::result_type> {
216 protected:
217 _Operation op;
218 typename _Operation::second_argument_type value;
219 public:
220 binder2nd(const _Operation& __x,
221 const typename _Operation::second_argument_type& __y)
222 : op(__x), value(__y) {}
223 typename _Operation::result_type
224 operator()(const typename _Operation::first_argument_type& __x) const {
225 return op(__x, value);
226 }
227 };
228
229 template <class _Operation, class _Tp>
230 inline binder2nd<_Operation>
231 bind2nd(const _Operation& __fn, const _Tp& __x)
232 {
233 typedef typename _Operation::second_argument_type _Arg2_type;
234 return binder2nd<_Operation>(__fn, _Arg2_type(__x));
235 }
236
237 // unary_compose and binary_compose (extensions, not part of the standard).
238
239 template <class _Operation1, class _Operation2>
240 class unary_compose
241 : public unary_function<typename _Operation2::argument_type,
242 typename _Operation1::result_type>
243 {
244 protected:
245 _Operation1 _M_fn1;
246 _Operation2 _M_fn2;
247 public:
248 unary_compose(const _Operation1& __x, const _Operation2& __y)
249 : _M_fn1(__x), _M_fn2(__y) {}
250 typename _Operation1::result_type
251 operator()(const typename _Operation2::argument_type& __x) const {
252 return _M_fn1(_M_fn2(__x));
253 }
254 };
255
256 template <class _Operation1, class _Operation2>
257 inline unary_compose<_Operation1,_Operation2>
258 compose1(const _Operation1& __fn1, const _Operation2& __fn2)
259 {
260 return unary_compose<_Operation1,_Operation2>(__fn1, __fn2);
261 }
262
263 template <class _Operation1, class _Operation2, class _Operation3>
264 class binary_compose
265 : public unary_function<typename _Operation2::argument_type,
266 typename _Operation1::result_type> {
267 protected:
268 _Operation1 _M_fn1;
269 _Operation2 _M_fn2;
270 _Operation3 _M_fn3;
271 public:
272 binary_compose(const _Operation1& __x, const _Operation2& __y,
273 const _Operation3& __z)
274 : _M_fn1(__x), _M_fn2(__y), _M_fn3(__z) { }
275 typename _Operation1::result_type
276 operator()(const typename _Operation2::argument_type& __x) const {
277 return _M_fn1(_M_fn2(__x), _M_fn3(__x));
278 }
279 };
280
281 template <class _Operation1, class _Operation2, class _Operation3>
282 inline binary_compose<_Operation1, _Operation2, _Operation3>
283 compose2(const _Operation1& __fn1, const _Operation2& __fn2,
284 const _Operation3& __fn3)
285 {
286 return binary_compose<_Operation1,_Operation2,_Operation3>
287 (__fn1, __fn2, __fn3);
288 }
289
290 template <class _Arg, class _Result>
291 class pointer_to_unary_function : public unary_function<_Arg, _Result> {
292 protected:
293 _Result (*_M_ptr)(_Arg);
294 public:
295 pointer_to_unary_function() {}
296 explicit pointer_to_unary_function(_Result (*__x)(_Arg)) : _M_ptr(__x) {}
297 _Result operator()(_Arg __x) const { return _M_ptr(__x); }
298 };
299
300 template <class _Arg, class _Result>
301 inline pointer_to_unary_function<_Arg, _Result> ptr_fun(_Result (*__x)(_Arg))
302 {
303 return pointer_to_unary_function<_Arg, _Result>(__x);
304 }
305
306 template <class _Arg1, class _Arg2, class _Result>
307 class pointer_to_binary_function :
308 public binary_function<_Arg1,_Arg2,_Result> {
309 protected:
310 _Result (*_M_ptr)(_Arg1, _Arg2);
311 public:
312 pointer_to_binary_function() {}
313 explicit pointer_to_binary_function(_Result (*__x)(_Arg1, _Arg2))
314 : _M_ptr(__x) {}
315 _Result operator()(_Arg1 __x, _Arg2 __y) const {
316 return _M_ptr(__x, __y);
317 }
318 };
319
320 template <class _Arg1, class _Arg2, class _Result>
321 inline pointer_to_binary_function<_Arg1,_Arg2,_Result>
322 ptr_fun(_Result (*__x)(_Arg1, _Arg2)) {
323 return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__x);
324 }
325
326 // identity is an extensions: it is not part of the standard.
327 template <class _Tp>
328 struct _Identity : public unary_function<_Tp,_Tp> {
329 _Tp& operator()(_Tp& __x) const { return __x; }
330 const _Tp& operator()(const _Tp& __x) const { return __x; }
331 };
332
333 template <class _Tp> struct identity : public _Identity<_Tp> {};
334
335 // select1st and select2nd are extensions: they are not part of the standard.
336 template <class _Pair>
337 struct _Select1st : public unary_function<_Pair, typename _Pair::first_type> {
338 typename _Pair::first_type& operator()(_Pair& __x) const {
339 return __x.first;
340 }
341 const typename _Pair::first_type& operator()(const _Pair& __x) const {
342 return __x.first;
343 }
344 };
345
346 template <class _Pair>
347 struct _Select2nd : public unary_function<_Pair, typename _Pair::second_type>
348 {
349 typename _Pair::second_type& operator()(_Pair& __x) const {
350 return __x.second;
351 }
352 const typename _Pair::second_type& operator()(const _Pair& __x) const {
353 return __x.second;
354 }
355 };
356
357 template <class _Pair> struct select1st : public _Select1st<_Pair> {};
358 template <class _Pair> struct select2nd : public _Select2nd<_Pair> {};
359
360 // project1st and project2nd are extensions: they are not part of the standard
361 template <class _Arg1, class _Arg2>
362 struct _Project1st : public binary_function<_Arg1, _Arg2, _Arg1> {
363 _Arg1 operator()(const _Arg1& __x, const _Arg2&) const { return __x; }
364 };
365
366 template <class _Arg1, class _Arg2>
367 struct _Project2nd : public binary_function<_Arg1, _Arg2, _Arg2> {
368 _Arg2 operator()(const _Arg1&, const _Arg2& __y) const { return __y; }
369 };
370
371 template <class _Arg1, class _Arg2>
372 struct project1st : public _Project1st<_Arg1, _Arg2> {};
373
374 template <class _Arg1, class _Arg2>
375 struct project2nd : public _Project2nd<_Arg1, _Arg2> {};
376
377 // constant_void_fun, constant_unary_fun, and constant_binary_fun are
378 // extensions: they are not part of the standard. (The same, of course,
379 // is true of the helper functions constant0, constant1, and constant2.)
380
381 template <class _Result>
382 struct _Constant_void_fun {
383 typedef _Result result_type;
384 result_type _M_val;
385
386 _Constant_void_fun(const result_type& __v) : _M_val(__v) {}
387 const result_type& operator()() const { return _M_val; }
388 };
389
390 template <class _Result, class _Argument>
391 struct _Constant_unary_fun {
392 typedef _Argument argument_type;
393 typedef _Result result_type;
394 result_type _M_val;
395
396 _Constant_unary_fun(const result_type& __v) : _M_val(__v) {}
397 const result_type& operator()(const _Argument&) const { return _M_val; }
398 };
399
400 template <class _Result, class _Arg1, class _Arg2>
401 struct _Constant_binary_fun {
402 typedef _Arg1 first_argument_type;
403 typedef _Arg2 second_argument_type;
404 typedef _Result result_type;
405 _Result _M_val;
406
407 _Constant_binary_fun(const _Result& __v) : _M_val(__v) {}
408 const result_type& operator()(const _Arg1&, const _Arg2&) const {
409 return _M_val;
410 }
411 };
412
413 template <class _Result>
414 struct constant_void_fun : public _Constant_void_fun<_Result> {
415 constant_void_fun(const _Result& __v) : _Constant_void_fun<_Result>(__v) {}
416 };
417
418
419 template <class _Result,
420 class _Argument = _Result>
421 struct constant_unary_fun : public _Constant_unary_fun<_Result, _Argument>
422 {
423 constant_unary_fun(const _Result& __v)
424 : _Constant_unary_fun<_Result, _Argument>(__v) {}
425 };
426
427
428 template <class _Result,
429 class _Arg1 = _Result,
430 class _Arg2 = _Arg1>
431 struct constant_binary_fun
432 : public _Constant_binary_fun<_Result, _Arg1, _Arg2>
433 {
434 constant_binary_fun(const _Result& __v)
435 : _Constant_binary_fun<_Result, _Arg1, _Arg2>(__v) {}
436 };
437
438 template <class _Result>
439 inline constant_void_fun<_Result> constant0(const _Result& __val)
440 {
441 return constant_void_fun<_Result>(__val);
442 }
443
444 template <class _Result>
445 inline constant_unary_fun<_Result,_Result> constant1(const _Result& __val)
446 {
447 return constant_unary_fun<_Result,_Result>(__val);
448 }
449
450 template <class _Result>
451 inline constant_binary_fun<_Result,_Result,_Result>
452 constant2(const _Result& __val)
453 {
454 return constant_binary_fun<_Result,_Result,_Result>(__val);
455 }
456
457 // subtractive_rng is an extension: it is not part of the standard.
458 // Note: this code assumes that int is 32 bits.
459 class subtractive_rng : public unary_function<unsigned int, unsigned int> {
460 private:
461 unsigned int _M_table[55];
462 size_t _M_index1;
463 size_t _M_index2;
464 public:
465 unsigned int operator()(unsigned int __limit) {
466 _M_index1 = (_M_index1 + 1) % 55;
467 _M_index2 = (_M_index2 + 1) % 55;
468 _M_table[_M_index1] = _M_table[_M_index1] - _M_table[_M_index2];
469 return _M_table[_M_index1] % __limit;
470 }
471
472 void _M_initialize(unsigned int __seed)
473 {
474 unsigned int __k = 1;
475 _M_table[54] = __seed;
476 size_t __i;
477 for (__i = 0; __i < 54; __i++) {
478 size_t __ii = (21 * (__i + 1) % 55) - 1;
479 _M_table[__ii] = __k;
480 __k = __seed - __k;
481 __seed = _M_table[__ii];
482 }
483 for (int __loop = 0; __loop < 4; __loop++) {
484 for (__i = 0; __i < 55; __i++)
485 _M_table[__i] = _M_table[__i] - _M_table[(1 + __i + 30) % 55];
486 }
487 _M_index1 = 0;
488 _M_index2 = 31;
489 }
490
491 subtractive_rng(unsigned int __seed) { _M_initialize(__seed); }
492 subtractive_rng() { _M_initialize(161803398u); }
493 };
494
495
496 // Adaptor function objects: pointers to member functions.
497
498 // There are a total of 16 = 2^4 function objects in this family.
499 // (1) Member functions taking no arguments vs member functions taking
500 // one argument.
501 // (2) Call through pointer vs call through reference.
502 // (3) Member function with void return type vs member function with
503 // non-void return type.
504 // (4) Const vs non-const member function.
505
506 // Note that choice (3) is nothing more than a workaround: according
507 // to the draft, compilers should handle void and non-void the same way.
508 // This feature is not yet widely implemented, though. You can only use
509 // member functions returning void if your compiler supports partial
510 // specialization.
511
512 // All of this complexity is in the function objects themselves. You can
513 // ignore it by using the helper function mem_fun and mem_fun_ref,
514 // which create whichever type of adaptor is appropriate.
515 // (mem_fun1 and mem_fun1_ref are no longer part of the C++ standard,
516 // but they are provided for backward compatibility.)
517
518
519 template <class _Ret, class _Tp>
520 class mem_fun_t : public unary_function<_Tp*,_Ret> {
521 public:
522 explicit mem_fun_t(_Ret (_Tp::*__pf)()) : _M_f(__pf) {}
523 _Ret operator()(_Tp* __p) const { return (__p->*_M_f)(); }
524 private:
525 _Ret (_Tp::*_M_f)();
526 };
527
528 template <class _Ret, class _Tp>
529 class const_mem_fun_t : public unary_function<const _Tp*,_Ret> {
530 public:
531 explicit const_mem_fun_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}
532 _Ret operator()(const _Tp* __p) const { return (__p->*_M_f)(); }
533 private:
534 _Ret (_Tp::*_M_f)() const;
535 };
536
537
538 template <class _Ret, class _Tp>
539 class mem_fun_ref_t : public unary_function<_Tp,_Ret> {
540 public:
541 explicit mem_fun_ref_t(_Ret (_Tp::*__pf)()) : _M_f(__pf) {}
542 _Ret operator()(_Tp& __r) const { return (__r.*_M_f)(); }
543 private:
544 _Ret (_Tp::*_M_f)();
545 };
546
547 template <class _Ret, class _Tp>
548 class const_mem_fun_ref_t : public unary_function<_Tp,_Ret> {
549 public:
550 explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}
551 _Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); }
552 private:
553 _Ret (_Tp::*_M_f)() const;
554 };
555
556 template <class _Ret, class _Tp, class _Arg>
557 class mem_fun1_t : public binary_function<_Tp*,_Arg,_Ret> {
558 public:
559 explicit mem_fun1_t(_Ret (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}
560 _Ret operator()(_Tp* __p, _Arg __x) const { return (__p->*_M_f)(__x); }
561 private:
562 _Ret (_Tp::*_M_f)(_Arg);
563 };
564
565 template <class _Ret, class _Tp, class _Arg>
566 class const_mem_fun1_t : public binary_function<const _Tp*,_Arg,_Ret> {
567 public:
568 explicit const_mem_fun1_t(_Ret (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {}
569 _Ret operator()(const _Tp* __p, _Arg __x) const
570 { return (__p->*_M_f)(__x); }
571 private:
572 _Ret (_Tp::*_M_f)(_Arg) const;
573 };
574
575 template <class _Ret, class _Tp, class _Arg>
576 class mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> {
577 public:
578 explicit mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}
579 _Ret operator()(_Tp& __r, _Arg __x) const { return (__r.*_M_f)(__x); }
580 private:
581 _Ret (_Tp::*_M_f)(_Arg);
582 };
583
584 template <class _Ret, class _Tp, class _Arg>
585 class const_mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> {
586 public:
587 explicit const_mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {}
588 _Ret operator()(const _Tp& __r, _Arg __x) const { return (__r.*_M_f)(__x); }
589 private:
590 _Ret (_Tp::*_M_f)(_Arg) const;
591 };
592
593 template <class _Tp>
594 class mem_fun_t<void, _Tp> : public unary_function<_Tp*,void> {
595 public:
596 explicit mem_fun_t(void (_Tp::*__pf)()) : _M_f(__pf) {}
597 void operator()(_Tp* __p) const { (__p->*_M_f)(); }
598 private:
599 void (_Tp::*_M_f)();
600 };
601
602 template <class _Tp>
603 class const_mem_fun_t<void, _Tp> : public unary_function<const _Tp*,void> {
604 public:
605 explicit const_mem_fun_t(void (_Tp::*__pf)() const) : _M_f(__pf) {}
606 void operator()(const _Tp* __p) const { (__p->*_M_f)(); }
607 private:
608 void (_Tp::*_M_f)() const;
609 };
610
611 template <class _Tp>
612 class mem_fun_ref_t<void, _Tp> : public unary_function<_Tp,void> {
613 public:
614 explicit mem_fun_ref_t(void (_Tp::*__pf)()) : _M_f(__pf) {}
615 void operator()(_Tp& __r) const { (__r.*_M_f)(); }
616 private:
617 void (_Tp::*_M_f)();
618 };
619
620 template <class _Tp>
621 class const_mem_fun_ref_t<void, _Tp> : public unary_function<_Tp,void> {
622 public:
623 explicit const_mem_fun_ref_t(void (_Tp::*__pf)() const) : _M_f(__pf) {}
624 void operator()(const _Tp& __r) const { (__r.*_M_f)(); }
625 private:
626 void (_Tp::*_M_f)() const;
627 };
628
629 template <class _Tp, class _Arg>
630 class mem_fun1_t<void, _Tp, _Arg> : public binary_function<_Tp*,_Arg,void> {
631 public:
632 explicit mem_fun1_t(void (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}
633 void operator()(_Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }
634 private:
635 void (_Tp::*_M_f)(_Arg);
636 };
637
638 template <class _Tp, class _Arg>
639 class const_mem_fun1_t<void, _Tp, _Arg>
640 : public binary_function<const _Tp*,_Arg,void> {
641 public:
642 explicit const_mem_fun1_t(void (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {}
643 void operator()(const _Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }
644 private:
645 void (_Tp::*_M_f)(_Arg) const;
646 };
647
648 template <class _Tp, class _Arg>
649 class mem_fun1_ref_t<void, _Tp, _Arg>
650 : public binary_function<_Tp,_Arg,void> {
651 public:
652 explicit mem_fun1_ref_t(void (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}
653 void operator()(_Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); }
654 private:
655 void (_Tp::*_M_f)(_Arg);
656 };
657
658 template <class _Tp, class _Arg>
659 class const_mem_fun1_ref_t<void, _Tp, _Arg>
660 : public binary_function<_Tp,_Arg,void> {
661 public:
662 explicit const_mem_fun1_ref_t(void (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {}
663 void operator()(const _Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); }
664 private:
665 void (_Tp::*_M_f)(_Arg) const;
666 };
667
668
669 // Mem_fun adaptor helper functions. There are only two:
670 // mem_fun and mem_fun_ref. (mem_fun1 and mem_fun1_ref
671 // are provided for backward compatibility, but they are no longer
672 // part of the C++ standard.)
673
674 template <class _Ret, class _Tp>
675 inline mem_fun_t<_Ret,_Tp> mem_fun(_Ret (_Tp::*__f)())
676 { return mem_fun_t<_Ret,_Tp>(__f); }
677
678 template <class _Ret, class _Tp>
679 inline const_mem_fun_t<_Ret,_Tp> mem_fun(_Ret (_Tp::*__f)() const)
680 { return const_mem_fun_t<_Ret,_Tp>(__f); }
681
682 template <class _Ret, class _Tp>
683 inline mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)())
684 { return mem_fun_ref_t<_Ret,_Tp>(__f); }
685
686 template <class _Ret, class _Tp>
687 inline const_mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)() const)
688 { return const_mem_fun_ref_t<_Ret,_Tp>(__f); }
689
690 template <class _Ret, class _Tp, class _Arg>
691 inline mem_fun1_t<_Ret,_Tp,_Arg> mem_fun(_Ret (_Tp::*__f)(_Arg))
692 { return mem_fun1_t<_Ret,_Tp,_Arg>(__f); }
693
694 template <class _Ret, class _Tp, class _Arg>
695 inline const_mem_fun1_t<_Ret,_Tp,_Arg> mem_fun(_Ret (_Tp::*__f)(_Arg) const)
696 { return const_mem_fun1_t<_Ret,_Tp,_Arg>(__f); }
697
698 template <class _Ret, class _Tp, class _Arg>
699 inline mem_fun1_ref_t<_Ret,_Tp,_Arg> mem_fun_ref(_Ret (_Tp::*__f)(_Arg))
700 { return mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }
701
702 template <class _Ret, class _Tp, class _Arg>
703 inline const_mem_fun1_ref_t<_Ret,_Tp,_Arg>
704 mem_fun_ref(_Ret (_Tp::*__f)(_Arg) const)
705 { return const_mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }
706
707 template <class _Ret, class _Tp, class _Arg>
708 inline mem_fun1_t<_Ret,_Tp,_Arg> mem_fun1(_Ret (_Tp::*__f)(_Arg))
709 { return mem_fun1_t<_Ret,_Tp,_Arg>(__f); }
710
711 template <class _Ret, class _Tp, class _Arg>
712 inline const_mem_fun1_t<_Ret,_Tp,_Arg> mem_fun1(_Ret (_Tp::*__f)(_Arg) const)
713 { return const_mem_fun1_t<_Ret,_Tp,_Arg>(__f); }
714
715 template <class _Ret, class _Tp, class _Arg>
716 inline mem_fun1_ref_t<_Ret,_Tp,_Arg> mem_fun1_ref(_Ret (_Tp::*__f)(_Arg))
717 { return mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }
718
719 template <class _Ret, class _Tp, class _Arg>
720 inline const_mem_fun1_ref_t<_Ret,_Tp,_Arg>
721 mem_fun1_ref(_Ret (_Tp::*__f)(_Arg) const)
722 { return const_mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }
723
724 } // namespace std
725
726 #endif /* __SGI_STL_INTERNAL_FUNCTION_H */
727
728 // Local Variables:
729 // mode:C++
730 // End: