Makefile.am (install-data-local): Remove pch-install rules.
[gcc.git] / libstdc++-v3 / include / bits / stl_function.h
1 // Functor implementations -*- C++ -*-
2
3 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 // Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
10 // any later version.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // USA.
21
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
30
31 /*
32 *
33 * Copyright (c) 1994
34 * Hewlett-Packard Company
35 *
36 * Permission to use, copy, modify, distribute and sell this software
37 * and its documentation for any purpose is hereby granted without fee,
38 * provided that the above copyright notice appear in all copies and
39 * that both that copyright notice and this permission notice appear
40 * in supporting documentation. Hewlett-Packard Company makes no
41 * representations about the suitability of this software for any
42 * purpose. It is provided "as is" without express or implied warranty.
43 *
44 *
45 * Copyright (c) 1996-1998
46 * Silicon Graphics Computer Systems, Inc.
47 *
48 * Permission to use, copy, modify, distribute and sell this software
49 * and its documentation for any purpose is hereby granted without fee,
50 * provided that the above copyright notice appear in all copies and
51 * that both that copyright notice and this permission notice appear
52 * in supporting documentation. Silicon Graphics makes no
53 * representations about the suitability of this software for any
54 * purpose. It is provided "as is" without express or implied warranty.
55 */
56
57 /** @file stl_function.h
58 * This is an internal header file, included by other library headers.
59 * You should not attempt to use it directly.
60 */
61
62 #ifndef _STL_FUNCTION_H
63 #define _STL_FUNCTION_H 1
64
65 _GLIBCXX_BEGIN_NAMESPACE(std)
66
67 // 20.3.1 base classes
68 /** @defgroup s20_3_1_base Functor Base Classes
69 * Function objects, or @e functors, are objects with an @c operator()
70 * defined and accessible. They can be passed as arguments to algorithm
71 * templates and used in place of a function pointer. Not only is the
72 * resulting expressiveness of the library increased, but the generated
73 * code can be more efficient than what you might write by hand. When we
74 * refer to "functors," then, generally we include function pointers in
75 * the description as well.
76 *
77 * Often, functors are only created as temporaries passed to algorithm
78 * calls, rather than being created as named variables.
79 *
80 * Two examples taken from the standard itself follow. To perform a
81 * by-element addition of two vectors @c a and @c b containing @c double,
82 * and put the result in @c a, use
83 * \code
84 * transform (a.begin(), a.end(), b.begin(), a.begin(), plus<double>());
85 * \endcode
86 * To negate every element in @c a, use
87 * \code
88 * transform(a.begin(), a.end(), a.begin(), negate<double>());
89 * \endcode
90 * The addition and negation functions will be inlined directly.
91 *
92 * The standard functors are derived from structs named @c unary_function
93 * and @c binary_function. These two classes contain nothing but typedefs,
94 * to aid in generic (template) programming. If you write your own
95 * functors, you might consider doing the same.
96 *
97 * @{
98 */
99 /**
100 * This is one of the @link s20_3_1_base functor base classes@endlink.
101 */
102 template <class _Arg, class _Result>
103 struct unary_function
104 {
105 typedef _Arg argument_type; ///< @c argument_type is the type of the
106 /// argument (no surprises here)
107
108 typedef _Result result_type; ///< @c result_type is the return type
109 };
110
111 /**
112 * This is one of the @link s20_3_1_base functor base classes@endlink.
113 */
114 template <class _Arg1, class _Arg2, class _Result>
115 struct binary_function
116 {
117 typedef _Arg1 first_argument_type; ///< the type of the first argument
118 /// (no surprises here)
119
120 typedef _Arg2 second_argument_type; ///< the type of the second argument
121 typedef _Result result_type; ///< type of the return type
122 };
123 /** @} */
124
125 // 20.3.2 arithmetic
126 /** @defgroup s20_3_2_arithmetic Arithmetic Classes
127
128 * Because basic math often needs to be done during an algorithm,
129 * the library provides functors for those operations. See the
130 * documentation for @link s20_3_1_base the base classes@endlink
131 * for examples of their use.
132 *
133 * @{
134 */
135 /// One of the @link s20_3_2_arithmetic math functors@endlink.
136 template <class _Tp>
137 struct plus : public binary_function<_Tp, _Tp, _Tp>
138 {
139 _Tp
140 operator()(const _Tp& __x, const _Tp& __y) const
141 { return __x + __y; }
142 };
143
144 /// One of the @link s20_3_2_arithmetic math functors@endlink.
145 template <class _Tp>
146 struct minus : public binary_function<_Tp, _Tp, _Tp>
147 {
148 _Tp
149 operator()(const _Tp& __x, const _Tp& __y) const
150 { return __x - __y; }
151 };
152
153 /// One of the @link s20_3_2_arithmetic math functors@endlink.
154 template <class _Tp>
155 struct multiplies : public binary_function<_Tp, _Tp, _Tp>
156 {
157 _Tp
158 operator()(const _Tp& __x, const _Tp& __y) const
159 { return __x * __y; }
160 };
161
162 /// One of the @link s20_3_2_arithmetic math functors@endlink.
163 template <class _Tp>
164 struct divides : public binary_function<_Tp, _Tp, _Tp>
165 {
166 _Tp
167 operator()(const _Tp& __x, const _Tp& __y) const
168 { return __x / __y; }
169 };
170
171 /// One of the @link s20_3_2_arithmetic math functors@endlink.
172 template <class _Tp>
173 struct modulus : public binary_function<_Tp, _Tp, _Tp>
174 {
175 _Tp
176 operator()(const _Tp& __x, const _Tp& __y) const
177 { return __x % __y; }
178 };
179
180 /// One of the @link s20_3_2_arithmetic math functors@endlink.
181 template <class _Tp>
182 struct negate : public unary_function<_Tp, _Tp>
183 {
184 _Tp
185 operator()(const _Tp& __x) const
186 { return -__x; }
187 };
188 /** @} */
189
190 // 20.3.3 comparisons
191 /** @defgroup s20_3_3_comparisons Comparison Classes
192 * The library provides six wrapper functors for all the basic comparisons
193 * in C++, like @c <.
194 *
195 * @{
196 */
197 /// One of the @link s20_3_3_comparisons comparison functors@endlink.
198 template <class _Tp>
199 struct equal_to : public binary_function<_Tp, _Tp, bool>
200 {
201 bool
202 operator()(const _Tp& __x, const _Tp& __y) const
203 { return __x == __y; }
204 };
205
206 /// One of the @link s20_3_3_comparisons comparison functors@endlink.
207 template <class _Tp>
208 struct not_equal_to : public binary_function<_Tp, _Tp, bool>
209 {
210 bool
211 operator()(const _Tp& __x, const _Tp& __y) const
212 { return __x != __y; }
213 };
214
215 /// One of the @link s20_3_3_comparisons comparison functors@endlink.
216 template <class _Tp>
217 struct greater : public binary_function<_Tp, _Tp, bool>
218 {
219 bool
220 operator()(const _Tp& __x, const _Tp& __y) const
221 { return __x > __y; }
222 };
223
224 /// One of the @link s20_3_3_comparisons comparison functors@endlink.
225 template <class _Tp>
226 struct less : public binary_function<_Tp, _Tp, bool>
227 {
228 bool
229 operator()(const _Tp& __x, const _Tp& __y) const
230 { return __x < __y; }
231 };
232
233 /// One of the @link s20_3_3_comparisons comparison functors@endlink.
234 template <class _Tp>
235 struct greater_equal : public binary_function<_Tp, _Tp, bool>
236 {
237 bool
238 operator()(const _Tp& __x, const _Tp& __y) const
239 { return __x >= __y; }
240 };
241
242 /// One of the @link s20_3_3_comparisons comparison functors@endlink.
243 template <class _Tp>
244 struct less_equal : public binary_function<_Tp, _Tp, bool>
245 {
246 bool
247 operator()(const _Tp& __x, const _Tp& __y) const
248 { return __x <= __y; }
249 };
250 /** @} */
251
252 // 20.3.4 logical operations
253 /** @defgroup s20_3_4_logical Boolean Operations Classes
254 * Here are wrapper functors for Boolean operations: @c &&, @c ||,
255 * and @c !.
256 *
257 * @{
258 */
259 /// One of the @link s20_3_4_logical Boolean operations functors@endlink.
260 template <class _Tp>
261 struct logical_and : public binary_function<_Tp, _Tp, bool>
262 {
263 bool
264 operator()(const _Tp& __x, const _Tp& __y) const
265 { return __x && __y; }
266 };
267
268 /// One of the @link s20_3_4_logical Boolean operations functors@endlink.
269 template <class _Tp>
270 struct logical_or : public binary_function<_Tp, _Tp, bool>
271 {
272 bool
273 operator()(const _Tp& __x, const _Tp& __y) const
274 { return __x || __y; }
275 };
276
277 /// One of the @link s20_3_4_logical Boolean operations functors@endlink.
278 template <class _Tp>
279 struct logical_not : public unary_function<_Tp, bool>
280 {
281 bool
282 operator()(const _Tp& __x) const
283 { return !__x; }
284 };
285 /** @} */
286
287 // _GLIBCXX_RESOLVE_LIB_DEFECTS
288 // DR 660. Missing Bitwise Operations.
289 template <class _Tp>
290 struct bit_and : public binary_function<_Tp, _Tp, _Tp>
291 {
292 _Tp
293 operator()(const _Tp& __x, const _Tp& __y) const
294 { return __x & __y; }
295 };
296
297 template <class _Tp>
298 struct bit_or : public binary_function<_Tp, _Tp, _Tp>
299 {
300 _Tp
301 operator()(const _Tp& __x, const _Tp& __y) const
302 { return __x | __y; }
303 };
304
305 template <class _Tp>
306 struct bit_xor : public binary_function<_Tp, _Tp, _Tp>
307 {
308 _Tp
309 operator()(const _Tp& __x, const _Tp& __y) const
310 { return __x ^ __y; }
311 };
312
313 // 20.3.5 negators
314 /** @defgroup s20_3_5_negators Negators
315 * The functions @c not1 and @c not2 each take a predicate functor
316 * and return an instance of @c unary_negate or
317 * @c binary_negate, respectively. These classes are functors whose
318 * @c operator() performs the stored predicate function and then returns
319 * the negation of the result.
320 *
321 * For example, given a vector of integers and a trivial predicate,
322 * \code
323 * struct IntGreaterThanThree
324 * : public std::unary_function<int, bool>
325 * {
326 * bool operator() (int x) { return x > 3; }
327 * };
328 *
329 * std::find_if (v.begin(), v.end(), not1(IntGreaterThanThree()));
330 * \endcode
331 * The call to @c find_if will locate the first index (i) of @c v for which
332 * "!(v[i] > 3)" is true.
333 *
334 * The not1/unary_negate combination works on predicates taking a single
335 * argument. The not2/binary_negate combination works on predicates which
336 * take two arguments.
337 *
338 * @{
339 */
340 /// One of the @link s20_3_5_negators negation functors@endlink.
341 template <class _Predicate>
342 class unary_negate
343 : public unary_function<typename _Predicate::argument_type, bool>
344 {
345 protected:
346 _Predicate _M_pred;
347 public:
348 explicit
349 unary_negate(const _Predicate& __x) : _M_pred(__x) {}
350
351 bool
352 operator()(const typename _Predicate::argument_type& __x) const
353 { return !_M_pred(__x); }
354 };
355
356 /// One of the @link s20_3_5_negators negation functors@endlink.
357 template <class _Predicate>
358 inline unary_negate<_Predicate>
359 not1(const _Predicate& __pred)
360 { return unary_negate<_Predicate>(__pred); }
361
362 /// One of the @link s20_3_5_negators negation functors@endlink.
363 template <class _Predicate>
364 class binary_negate
365 : public binary_function<typename _Predicate::first_argument_type,
366 typename _Predicate::second_argument_type, bool>
367 {
368 protected:
369 _Predicate _M_pred;
370
371 public:
372 explicit
373 binary_negate(const _Predicate& __x) : _M_pred(__x) { }
374
375 bool
376 operator()(const typename _Predicate::first_argument_type& __x,
377 const typename _Predicate::second_argument_type& __y) const
378 { return !_M_pred(__x, __y); }
379 };
380
381 /// One of the @link s20_3_5_negators negation functors@endlink.
382 template <class _Predicate>
383 inline binary_negate<_Predicate>
384 not2(const _Predicate& __pred)
385 { return binary_negate<_Predicate>(__pred); }
386 /** @} */
387
388 // 20.3.6 binders
389 /** @defgroup s20_3_6_binder Binder Classes
390 * Binders turn functions/functors with two arguments into functors with
391 * a single argument, storing an argument to be applied later. For
392 * example, a variable @c B of type @c binder1st is constructed from a
393 * functor @c f and an argument @c x. Later, B's @c operator() is called
394 * with a single argument @c y. The return value is the value of @c f(x,y).
395 * @c B can be "called" with various arguments (y1, y2, ...) and will in
396 * turn call @c f(x,y1), @c f(x,y2), ...
397 *
398 * The function @c bind1st is provided to save some typing. It takes the
399 * function and an argument as parameters, and returns an instance of
400 * @c binder1st.
401 *
402 * The type @c binder2nd and its creator function @c bind2nd do the same
403 * thing, but the stored argument is passed as the second parameter instead
404 * of the first, e.g., @c bind2nd(std::minus<float>,1.3) will create a
405 * functor whose @c operator() accepts a floating-point number, subtracts
406 * 1.3 from it, and returns the result. (If @c bind1st had been used,
407 * the functor would perform "1.3 - x" instead.
408 *
409 * Creator-wrapper functions like @c bind1st are intended to be used in
410 * calling algorithms. Their return values will be temporary objects.
411 * (The goal is to not require you to type names like
412 * @c std::binder1st<std::plus<int>> for declaring a variable to hold the
413 * return value from @c bind1st(std::plus<int>,5).
414 *
415 * These become more useful when combined with the composition functions.
416 *
417 * @{
418 */
419 /// One of the @link s20_3_6_binder binder functors@endlink.
420 template <class _Operation>
421 class binder1st
422 : public unary_function<typename _Operation::second_argument_type,
423 typename _Operation::result_type>
424 {
425 protected:
426 _Operation op;
427 typename _Operation::first_argument_type value;
428 public:
429 binder1st(const _Operation& __x,
430 const typename _Operation::first_argument_type& __y)
431 : op(__x), value(__y) {}
432
433 typename _Operation::result_type
434 operator()(const typename _Operation::second_argument_type& __x) const
435 { return op(value, __x); }
436
437 // _GLIBCXX_RESOLVE_LIB_DEFECTS
438 // 109. Missing binders for non-const sequence elements
439 typename _Operation::result_type
440 operator()(typename _Operation::second_argument_type& __x) const
441 { return op(value, __x); }
442 };
443
444 /// One of the @link s20_3_6_binder binder functors@endlink.
445 template <class _Operation, class _Tp>
446 inline binder1st<_Operation>
447 bind1st(const _Operation& __fn, const _Tp& __x)
448 {
449 typedef typename _Operation::first_argument_type _Arg1_type;
450 return binder1st<_Operation>(__fn, _Arg1_type(__x));
451 }
452
453 /// One of the @link s20_3_6_binder binder functors@endlink.
454 template <class _Operation>
455 class binder2nd
456 : public unary_function<typename _Operation::first_argument_type,
457 typename _Operation::result_type>
458 {
459 protected:
460 _Operation op;
461 typename _Operation::second_argument_type value;
462 public:
463 binder2nd(const _Operation& __x,
464 const typename _Operation::second_argument_type& __y)
465 : op(__x), value(__y) {}
466
467 typename _Operation::result_type
468 operator()(const typename _Operation::first_argument_type& __x) const
469 { return op(__x, value); }
470
471 // _GLIBCXX_RESOLVE_LIB_DEFECTS
472 // 109. Missing binders for non-const sequence elements
473 typename _Operation::result_type
474 operator()(typename _Operation::first_argument_type& __x) const
475 { return op(__x, value); }
476 };
477
478 /// One of the @link s20_3_6_binder binder functors@endlink.
479 template <class _Operation, class _Tp>
480 inline binder2nd<_Operation>
481 bind2nd(const _Operation& __fn, const _Tp& __x)
482 {
483 typedef typename _Operation::second_argument_type _Arg2_type;
484 return binder2nd<_Operation>(__fn, _Arg2_type(__x));
485 }
486 /** @} */
487
488 // 20.3.7 adaptors pointers functions
489 /** @defgroup s20_3_7_adaptors Adaptors for pointers to functions
490 * The advantage of function objects over pointers to functions is that
491 * the objects in the standard library declare nested typedefs describing
492 * their argument and result types with uniform names (e.g., @c result_type
493 * from the base classes @c unary_function and @c binary_function).
494 * Sometimes those typedefs are required, not just optional.
495 *
496 * Adaptors are provided to turn pointers to unary (single-argument) and
497 * binary (double-argument) functions into function objects. The
498 * long-winded functor @c pointer_to_unary_function is constructed with a
499 * function pointer @c f, and its @c operator() called with argument @c x
500 * returns @c f(x). The functor @c pointer_to_binary_function does the same
501 * thing, but with a double-argument @c f and @c operator().
502 *
503 * The function @c ptr_fun takes a pointer-to-function @c f and constructs
504 * an instance of the appropriate functor.
505 *
506 * @{
507 */
508 /// One of the @link s20_3_7_adaptors adaptors for function pointers@endlink.
509 template <class _Arg, class _Result>
510 class pointer_to_unary_function : public unary_function<_Arg, _Result>
511 {
512 protected:
513 _Result (*_M_ptr)(_Arg);
514 public:
515 pointer_to_unary_function() {}
516
517 explicit
518 pointer_to_unary_function(_Result (*__x)(_Arg))
519 : _M_ptr(__x) {}
520
521 _Result
522 operator()(_Arg __x) const
523 { return _M_ptr(__x); }
524 };
525
526 /// One of the @link s20_3_7_adaptors adaptors for function pointers@endlink.
527 template <class _Arg, class _Result>
528 inline pointer_to_unary_function<_Arg, _Result>
529 ptr_fun(_Result (*__x)(_Arg))
530 { return pointer_to_unary_function<_Arg, _Result>(__x); }
531
532 /// One of the @link s20_3_7_adaptors adaptors for function pointers@endlink.
533 template <class _Arg1, class _Arg2, class _Result>
534 class pointer_to_binary_function
535 : public binary_function<_Arg1, _Arg2, _Result>
536 {
537 protected:
538 _Result (*_M_ptr)(_Arg1, _Arg2);
539 public:
540 pointer_to_binary_function() {}
541
542 explicit
543 pointer_to_binary_function(_Result (*__x)(_Arg1, _Arg2))
544 : _M_ptr(__x) {}
545
546 _Result
547 operator()(_Arg1 __x, _Arg2 __y) const
548 { return _M_ptr(__x, __y); }
549 };
550
551 /// One of the @link s20_3_7_adaptors adaptors for function pointers@endlink.
552 template <class _Arg1, class _Arg2, class _Result>
553 inline pointer_to_binary_function<_Arg1, _Arg2, _Result>
554 ptr_fun(_Result (*__x)(_Arg1, _Arg2))
555 { return pointer_to_binary_function<_Arg1, _Arg2, _Result>(__x); }
556 /** @} */
557
558 template <class _Tp>
559 struct _Identity : public unary_function<_Tp,_Tp>
560 {
561 _Tp&
562 operator()(_Tp& __x) const
563 { return __x; }
564
565 const _Tp&
566 operator()(const _Tp& __x) const
567 { return __x; }
568 };
569
570 template <class _Pair>
571 struct _Select1st : public unary_function<_Pair,
572 typename _Pair::first_type>
573 {
574 typename _Pair::first_type&
575 operator()(_Pair& __x) const
576 { return __x.first; }
577
578 const typename _Pair::first_type&
579 operator()(const _Pair& __x) const
580 { return __x.first; }
581 };
582
583 template <class _Pair>
584 struct _Select2nd : public unary_function<_Pair,
585 typename _Pair::second_type>
586 {
587 typename _Pair::second_type&
588 operator()(_Pair& __x) const
589 { return __x.second; }
590
591 const typename _Pair::second_type&
592 operator()(const _Pair& __x) const
593 { return __x.second; }
594 };
595
596 // 20.3.8 adaptors pointers members
597 /** @defgroup s20_3_8_memadaptors Adaptors for pointers to members
598 * There are a total of 8 = 2^3 function objects in this family.
599 * (1) Member functions taking no arguments vs member functions taking
600 * one argument.
601 * (2) Call through pointer vs call through reference.
602 * (3) Const vs non-const member function.
603 *
604 * All of this complexity is in the function objects themselves. You can
605 * ignore it by using the helper function mem_fun and mem_fun_ref,
606 * which create whichever type of adaptor is appropriate.
607 *
608 * @{
609 */
610 /// One of the @link s20_3_8_memadaptors adaptors for member
611 /// pointers@endlink.
612 template <class _Ret, class _Tp>
613 class mem_fun_t : public unary_function<_Tp*, _Ret>
614 {
615 public:
616 explicit
617 mem_fun_t(_Ret (_Tp::*__pf)())
618 : _M_f(__pf) {}
619
620 _Ret
621 operator()(_Tp* __p) const
622 { return (__p->*_M_f)(); }
623 private:
624 _Ret (_Tp::*_M_f)();
625 };
626
627 /// One of the @link s20_3_8_memadaptors adaptors for member
628 /// pointers@endlink.
629 template <class _Ret, class _Tp>
630 class const_mem_fun_t : public unary_function<const _Tp*, _Ret>
631 {
632 public:
633 explicit
634 const_mem_fun_t(_Ret (_Tp::*__pf)() const)
635 : _M_f(__pf) {}
636
637 _Ret
638 operator()(const _Tp* __p) const
639 { return (__p->*_M_f)(); }
640 private:
641 _Ret (_Tp::*_M_f)() const;
642 };
643
644 /// One of the @link s20_3_8_memadaptors adaptors for member
645 /// pointers@endlink.
646 template <class _Ret, class _Tp>
647 class mem_fun_ref_t : public unary_function<_Tp, _Ret>
648 {
649 public:
650 explicit
651 mem_fun_ref_t(_Ret (_Tp::*__pf)())
652 : _M_f(__pf) {}
653
654 _Ret
655 operator()(_Tp& __r) const
656 { return (__r.*_M_f)(); }
657 private:
658 _Ret (_Tp::*_M_f)();
659 };
660
661 /// One of the @link s20_3_8_memadaptors adaptors for member
662 /// pointers@endlink.
663 template <class _Ret, class _Tp>
664 class const_mem_fun_ref_t : public unary_function<_Tp, _Ret>
665 {
666 public:
667 explicit
668 const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const)
669 : _M_f(__pf) {}
670
671 _Ret
672 operator()(const _Tp& __r) const
673 { return (__r.*_M_f)(); }
674 private:
675 _Ret (_Tp::*_M_f)() const;
676 };
677
678 /// One of the @link s20_3_8_memadaptors adaptors for member
679 /// pointers@endlink.
680 template <class _Ret, class _Tp, class _Arg>
681 class mem_fun1_t : public binary_function<_Tp*, _Arg, _Ret>
682 {
683 public:
684 explicit
685 mem_fun1_t(_Ret (_Tp::*__pf)(_Arg))
686 : _M_f(__pf) {}
687
688 _Ret
689 operator()(_Tp* __p, _Arg __x) const
690 { return (__p->*_M_f)(__x); }
691 private:
692 _Ret (_Tp::*_M_f)(_Arg);
693 };
694
695 /// One of the @link s20_3_8_memadaptors adaptors for member
696 /// pointers@endlink.
697 template <class _Ret, class _Tp, class _Arg>
698 class const_mem_fun1_t : public binary_function<const _Tp*, _Arg, _Ret>
699 {
700 public:
701 explicit
702 const_mem_fun1_t(_Ret (_Tp::*__pf)(_Arg) const)
703 : _M_f(__pf) {}
704
705 _Ret
706 operator()(const _Tp* __p, _Arg __x) const
707 { return (__p->*_M_f)(__x); }
708 private:
709 _Ret (_Tp::*_M_f)(_Arg) const;
710 };
711
712 /// One of the @link s20_3_8_memadaptors adaptors for member
713 /// pointers@endlink.
714 template <class _Ret, class _Tp, class _Arg>
715 class mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret>
716 {
717 public:
718 explicit
719 mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg))
720 : _M_f(__pf) {}
721
722 _Ret
723 operator()(_Tp& __r, _Arg __x) const
724 { return (__r.*_M_f)(__x); }
725 private:
726 _Ret (_Tp::*_M_f)(_Arg);
727 };
728
729 /// One of the @link s20_3_8_memadaptors adaptors for member
730 /// pointers@endlink.
731 template <class _Ret, class _Tp, class _Arg>
732 class const_mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret>
733 {
734 public:
735 explicit
736 const_mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg) const)
737 : _M_f(__pf) {}
738
739 _Ret
740 operator()(const _Tp& __r, _Arg __x) const
741 { return (__r.*_M_f)(__x); }
742 private:
743 _Ret (_Tp::*_M_f)(_Arg) const;
744 };
745
746 // Mem_fun adaptor helper functions. There are only two:
747 // mem_fun and mem_fun_ref.
748 template <class _Ret, class _Tp>
749 inline mem_fun_t<_Ret, _Tp>
750 mem_fun(_Ret (_Tp::*__f)())
751 { return mem_fun_t<_Ret, _Tp>(__f); }
752
753 template <class _Ret, class _Tp>
754 inline const_mem_fun_t<_Ret, _Tp>
755 mem_fun(_Ret (_Tp::*__f)() const)
756 { return const_mem_fun_t<_Ret, _Tp>(__f); }
757
758 template <class _Ret, class _Tp>
759 inline mem_fun_ref_t<_Ret, _Tp>
760 mem_fun_ref(_Ret (_Tp::*__f)())
761 { return mem_fun_ref_t<_Ret, _Tp>(__f); }
762
763 template <class _Ret, class _Tp>
764 inline const_mem_fun_ref_t<_Ret, _Tp>
765 mem_fun_ref(_Ret (_Tp::*__f)() const)
766 { return const_mem_fun_ref_t<_Ret, _Tp>(__f); }
767
768 template <class _Ret, class _Tp, class _Arg>
769 inline mem_fun1_t<_Ret, _Tp, _Arg>
770 mem_fun(_Ret (_Tp::*__f)(_Arg))
771 { return mem_fun1_t<_Ret, _Tp, _Arg>(__f); }
772
773 template <class _Ret, class _Tp, class _Arg>
774 inline const_mem_fun1_t<_Ret, _Tp, _Arg>
775 mem_fun(_Ret (_Tp::*__f)(_Arg) const)
776 { return const_mem_fun1_t<_Ret, _Tp, _Arg>(__f); }
777
778 template <class _Ret, class _Tp, class _Arg>
779 inline mem_fun1_ref_t<_Ret, _Tp, _Arg>
780 mem_fun_ref(_Ret (_Tp::*__f)(_Arg))
781 { return mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); }
782
783 template <class _Ret, class _Tp, class _Arg>
784 inline const_mem_fun1_ref_t<_Ret, _Tp, _Arg>
785 mem_fun_ref(_Ret (_Tp::*__f)(_Arg) const)
786 { return const_mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); }
787
788 /** @} */
789
790 _GLIBCXX_END_NAMESPACE
791
792 #endif /* _STL_FUNCTION_H */