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