libstdc++
|
00001 // Functor implementations -*- C++ -*- 00002 00003 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010, 00004 // 2011, 2012 00005 // Free Software Foundation, Inc. 00006 // 00007 // This file is part of the GNU ISO C++ Library. This library is free 00008 // software; you can redistribute it and/or modify it under the 00009 // terms of the GNU General Public License as published by the 00010 // Free Software Foundation; either version 3, or (at your option) 00011 // any later version. 00012 00013 // This library is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 00018 // Under Section 7 of GPL version 3, you are granted additional 00019 // permissions described in the GCC Runtime Library Exception, version 00020 // 3.1, as published by the Free Software Foundation. 00021 00022 // You should have received a copy of the GNU General Public License and 00023 // a copy of the GCC Runtime Library Exception along with this program; 00024 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00025 // <http://www.gnu.org/licenses/>. 00026 00027 /* 00028 * 00029 * Copyright (c) 1994 00030 * Hewlett-Packard Company 00031 * 00032 * Permission to use, copy, modify, distribute and sell this software 00033 * and its documentation for any purpose is hereby granted without fee, 00034 * provided that the above copyright notice appear in all copies and 00035 * that both that copyright notice and this permission notice appear 00036 * in supporting documentation. Hewlett-Packard Company makes no 00037 * representations about the suitability of this software for any 00038 * purpose. It is provided "as is" without express or implied warranty. 00039 * 00040 * 00041 * Copyright (c) 1996-1998 00042 * Silicon Graphics Computer Systems, Inc. 00043 * 00044 * Permission to use, copy, modify, distribute and sell this software 00045 * and its documentation for any purpose is hereby granted without fee, 00046 * provided that the above copyright notice appear in all copies and 00047 * that both that copyright notice and this permission notice appear 00048 * in supporting documentation. Silicon Graphics makes no 00049 * representations about the suitability of this software for any 00050 * purpose. It is provided "as is" without express or implied warranty. 00051 */ 00052 00053 /** @file bits/stl_function.h 00054 * This is an internal header file, included by other library headers. 00055 * Do not attempt to use it directly. @headername{functional} 00056 */ 00057 00058 #ifndef _STL_FUNCTION_H 00059 #define _STL_FUNCTION_H 1 00060 00061 namespace std _GLIBCXX_VISIBILITY(default) 00062 { 00063 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00064 00065 // 20.3.1 base classes 00066 /** @defgroup functors Function Objects 00067 * @ingroup utilities 00068 * 00069 * Function objects, or @e functors, are objects with an @c operator() 00070 * defined and accessible. They can be passed as arguments to algorithm 00071 * templates and used in place of a function pointer. Not only is the 00072 * resulting expressiveness of the library increased, but the generated 00073 * code can be more efficient than what you might write by hand. When we 00074 * refer to @a functors, then, generally we include function pointers in 00075 * the description as well. 00076 * 00077 * Often, functors are only created as temporaries passed to algorithm 00078 * calls, rather than being created as named variables. 00079 * 00080 * Two examples taken from the standard itself follow. To perform a 00081 * by-element addition of two vectors @c a and @c b containing @c double, 00082 * and put the result in @c a, use 00083 * \code 00084 * transform (a.begin(), a.end(), b.begin(), a.begin(), plus<double>()); 00085 * \endcode 00086 * To negate every element in @c a, use 00087 * \code 00088 * transform(a.begin(), a.end(), a.begin(), negate<double>()); 00089 * \endcode 00090 * The addition and negation functions will be inlined directly. 00091 * 00092 * The standard functors are derived from structs named @c unary_function 00093 * and @c binary_function. These two classes contain nothing but typedefs, 00094 * to aid in generic (template) programming. If you write your own 00095 * functors, you might consider doing the same. 00096 * 00097 * @{ 00098 */ 00099 /** 00100 * This is one of the @link functors functor base classes@endlink. 00101 */ 00102 template<typename _Arg, typename _Result> 00103 struct unary_function 00104 { 00105 /// @c argument_type is the type of the argument 00106 typedef _Arg argument_type; 00107 00108 /// @c result_type is the return type 00109 typedef _Result result_type; 00110 }; 00111 00112 /** 00113 * This is one of the @link functors functor base classes@endlink. 00114 */ 00115 template<typename _Arg1, typename _Arg2, typename _Result> 00116 struct binary_function 00117 { 00118 /// @c first_argument_type is the type of the first argument 00119 typedef _Arg1 first_argument_type; 00120 00121 /// @c second_argument_type is the type of the second argument 00122 typedef _Arg2 second_argument_type; 00123 00124 /// @c result_type is the return type 00125 typedef _Result result_type; 00126 }; 00127 /** @} */ 00128 00129 // 20.3.2 arithmetic 00130 /** @defgroup arithmetic_functors Arithmetic Classes 00131 * @ingroup functors 00132 * 00133 * Because basic math often needs to be done during an algorithm, 00134 * the library provides functors for those operations. See the 00135 * documentation for @link functors the base classes@endlink 00136 * for examples of their use. 00137 * 00138 * @{ 00139 */ 00140 /// One of the @link arithmetic_functors math functors@endlink. 00141 template<typename _Tp> 00142 struct plus : public binary_function<_Tp, _Tp, _Tp> 00143 { 00144 _Tp 00145 operator()(const _Tp& __x, const _Tp& __y) const 00146 { return __x + __y; } 00147 }; 00148 00149 /// One of the @link arithmetic_functors math functors@endlink. 00150 template<typename _Tp> 00151 struct minus : public binary_function<_Tp, _Tp, _Tp> 00152 { 00153 _Tp 00154 operator()(const _Tp& __x, const _Tp& __y) const 00155 { return __x - __y; } 00156 }; 00157 00158 /// One of the @link arithmetic_functors math functors@endlink. 00159 template<typename _Tp> 00160 struct multiplies : public binary_function<_Tp, _Tp, _Tp> 00161 { 00162 _Tp 00163 operator()(const _Tp& __x, const _Tp& __y) const 00164 { return __x * __y; } 00165 }; 00166 00167 /// One of the @link arithmetic_functors math functors@endlink. 00168 template<typename _Tp> 00169 struct divides : public binary_function<_Tp, _Tp, _Tp> 00170 { 00171 _Tp 00172 operator()(const _Tp& __x, const _Tp& __y) const 00173 { return __x / __y; } 00174 }; 00175 00176 /// One of the @link arithmetic_functors math functors@endlink. 00177 template<typename _Tp> 00178 struct modulus : public binary_function<_Tp, _Tp, _Tp> 00179 { 00180 _Tp 00181 operator()(const _Tp& __x, const _Tp& __y) const 00182 { return __x % __y; } 00183 }; 00184 00185 /// One of the @link arithmetic_functors math functors@endlink. 00186 template<typename _Tp> 00187 struct negate : public unary_function<_Tp, _Tp> 00188 { 00189 _Tp 00190 operator()(const _Tp& __x) const 00191 { return -__x; } 00192 }; 00193 /** @} */ 00194 00195 // 20.3.3 comparisons 00196 /** @defgroup comparison_functors Comparison Classes 00197 * @ingroup functors 00198 * 00199 * The library provides six wrapper functors for all the basic comparisons 00200 * in C++, like @c <. 00201 * 00202 * @{ 00203 */ 00204 /// One of the @link comparison_functors comparison functors@endlink. 00205 template<typename _Tp> 00206 struct equal_to : public binary_function<_Tp, _Tp, bool> 00207 { 00208 bool 00209 operator()(const _Tp& __x, const _Tp& __y) const 00210 { return __x == __y; } 00211 }; 00212 00213 /// One of the @link comparison_functors comparison functors@endlink. 00214 template<typename _Tp> 00215 struct not_equal_to : public binary_function<_Tp, _Tp, bool> 00216 { 00217 bool 00218 operator()(const _Tp& __x, const _Tp& __y) const 00219 { return __x != __y; } 00220 }; 00221 00222 /// One of the @link comparison_functors comparison functors@endlink. 00223 template<typename _Tp> 00224 struct greater : public binary_function<_Tp, _Tp, bool> 00225 { 00226 bool 00227 operator()(const _Tp& __x, const _Tp& __y) const 00228 { return __x > __y; } 00229 }; 00230 00231 /// One of the @link comparison_functors comparison functors@endlink. 00232 template<typename _Tp> 00233 struct less : public binary_function<_Tp, _Tp, bool> 00234 { 00235 bool 00236 operator()(const _Tp& __x, const _Tp& __y) const 00237 { return __x < __y; } 00238 }; 00239 00240 /// One of the @link comparison_functors comparison functors@endlink. 00241 template<typename _Tp> 00242 struct greater_equal : public binary_function<_Tp, _Tp, bool> 00243 { 00244 bool 00245 operator()(const _Tp& __x, const _Tp& __y) const 00246 { return __x >= __y; } 00247 }; 00248 00249 /// One of the @link comparison_functors comparison functors@endlink. 00250 template<typename _Tp> 00251 struct less_equal : public binary_function<_Tp, _Tp, bool> 00252 { 00253 bool 00254 operator()(const _Tp& __x, const _Tp& __y) const 00255 { return __x <= __y; } 00256 }; 00257 /** @} */ 00258 00259 // 20.3.4 logical operations 00260 /** @defgroup logical_functors Boolean Operations Classes 00261 * @ingroup functors 00262 * 00263 * Here are wrapper functors for Boolean operations: @c &&, @c ||, 00264 * and @c !. 00265 * 00266 * @{ 00267 */ 00268 /// One of the @link logical_functors Boolean operations functors@endlink. 00269 template<typename _Tp> 00270 struct logical_and : public binary_function<_Tp, _Tp, bool> 00271 { 00272 bool 00273 operator()(const _Tp& __x, const _Tp& __y) const 00274 { return __x && __y; } 00275 }; 00276 00277 /// One of the @link logical_functors Boolean operations functors@endlink. 00278 template<typename _Tp> 00279 struct logical_or : public binary_function<_Tp, _Tp, bool> 00280 { 00281 bool 00282 operator()(const _Tp& __x, const _Tp& __y) const 00283 { return __x || __y; } 00284 }; 00285 00286 /// One of the @link logical_functors Boolean operations functors@endlink. 00287 template<typename _Tp> 00288 struct logical_not : public unary_function<_Tp, bool> 00289 { 00290 bool 00291 operator()(const _Tp& __x) const 00292 { return !__x; } 00293 }; 00294 /** @} */ 00295 00296 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00297 // DR 660. Missing Bitwise Operations. 00298 template<typename _Tp> 00299 struct bit_and : public binary_function<_Tp, _Tp, _Tp> 00300 { 00301 _Tp 00302 operator()(const _Tp& __x, const _Tp& __y) const 00303 { return __x & __y; } 00304 }; 00305 00306 template<typename _Tp> 00307 struct bit_or : public binary_function<_Tp, _Tp, _Tp> 00308 { 00309 _Tp 00310 operator()(const _Tp& __x, const _Tp& __y) const 00311 { return __x | __y; } 00312 }; 00313 00314 template<typename _Tp> 00315 struct bit_xor : public binary_function<_Tp, _Tp, _Tp> 00316 { 00317 _Tp 00318 operator()(const _Tp& __x, const _Tp& __y) const 00319 { return __x ^ __y; } 00320 }; 00321 00322 // 20.3.5 negators 00323 /** @defgroup negators Negators 00324 * @ingroup functors 00325 * 00326 * The functions @c not1 and @c not2 each take a predicate functor 00327 * and return an instance of @c unary_negate or 00328 * @c binary_negate, respectively. These classes are functors whose 00329 * @c operator() performs the stored predicate function and then returns 00330 * the negation of the result. 00331 * 00332 * For example, given a vector of integers and a trivial predicate, 00333 * \code 00334 * struct IntGreaterThanThree 00335 * : public std::unary_function<int, bool> 00336 * { 00337 * bool operator() (int x) { return x > 3; } 00338 * }; 00339 * 00340 * std::find_if (v.begin(), v.end(), not1(IntGreaterThanThree())); 00341 * \endcode 00342 * The call to @c find_if will locate the first index (i) of @c v for which 00343 * <code>!(v[i] > 3)</code> is true. 00344 * 00345 * The not1/unary_negate combination works on predicates taking a single 00346 * argument. The not2/binary_negate combination works on predicates which 00347 * take two arguments. 00348 * 00349 * @{ 00350 */ 00351 /// One of the @link negators negation functors@endlink. 00352 template<typename _Predicate> 00353 class unary_negate 00354 : public unary_function<typename _Predicate::argument_type, bool> 00355 { 00356 protected: 00357 _Predicate _M_pred; 00358 00359 public: 00360 explicit 00361 unary_negate(const _Predicate& __x) : _M_pred(__x) { } 00362 00363 bool 00364 operator()(const typename _Predicate::argument_type& __x) const 00365 { return !_M_pred(__x); } 00366 }; 00367 00368 /// One of the @link negators negation functors@endlink. 00369 template<typename _Predicate> 00370 inline unary_negate<_Predicate> 00371 not1(const _Predicate& __pred) 00372 { return unary_negate<_Predicate>(__pred); } 00373 00374 /// One of the @link negators negation functors@endlink. 00375 template<typename _Predicate> 00376 class binary_negate 00377 : public binary_function<typename _Predicate::first_argument_type, 00378 typename _Predicate::second_argument_type, bool> 00379 { 00380 protected: 00381 _Predicate _M_pred; 00382 00383 public: 00384 explicit 00385 binary_negate(const _Predicate& __x) : _M_pred(__x) { } 00386 00387 bool 00388 operator()(const typename _Predicate::first_argument_type& __x, 00389 const typename _Predicate::second_argument_type& __y) const 00390 { return !_M_pred(__x, __y); } 00391 }; 00392 00393 /// One of the @link negators negation functors@endlink. 00394 template<typename _Predicate> 00395 inline binary_negate<_Predicate> 00396 not2(const _Predicate& __pred) 00397 { return binary_negate<_Predicate>(__pred); } 00398 /** @} */ 00399 00400 // 20.3.7 adaptors pointers functions 00401 /** @defgroup pointer_adaptors Adaptors for pointers to functions 00402 * @ingroup functors 00403 * 00404 * The advantage of function objects over pointers to functions is that 00405 * the objects in the standard library declare nested typedefs describing 00406 * their argument and result types with uniform names (e.g., @c result_type 00407 * from the base classes @c unary_function and @c binary_function). 00408 * Sometimes those typedefs are required, not just optional. 00409 * 00410 * Adaptors are provided to turn pointers to unary (single-argument) and 00411 * binary (double-argument) functions into function objects. The 00412 * long-winded functor @c pointer_to_unary_function is constructed with a 00413 * function pointer @c f, and its @c operator() called with argument @c x 00414 * returns @c f(x). The functor @c pointer_to_binary_function does the same 00415 * thing, but with a double-argument @c f and @c operator(). 00416 * 00417 * The function @c ptr_fun takes a pointer-to-function @c f and constructs 00418 * an instance of the appropriate functor. 00419 * 00420 * @{ 00421 */ 00422 /// One of the @link pointer_adaptors adaptors for function pointers@endlink. 00423 template<typename _Arg, typename _Result> 00424 class pointer_to_unary_function : public unary_function<_Arg, _Result> 00425 { 00426 protected: 00427 _Result (*_M_ptr)(_Arg); 00428 00429 public: 00430 pointer_to_unary_function() { } 00431 00432 explicit 00433 pointer_to_unary_function(_Result (*__x)(_Arg)) 00434 : _M_ptr(__x) { } 00435 00436 _Result 00437 operator()(_Arg __x) const 00438 { return _M_ptr(__x); } 00439 }; 00440 00441 /// One of the @link pointer_adaptors adaptors for function pointers@endlink. 00442 template<typename _Arg, typename _Result> 00443 inline pointer_to_unary_function<_Arg, _Result> 00444 ptr_fun(_Result (*__x)(_Arg)) 00445 { return pointer_to_unary_function<_Arg, _Result>(__x); } 00446 00447 /// One of the @link pointer_adaptors adaptors for function pointers@endlink. 00448 template<typename _Arg1, typename _Arg2, typename _Result> 00449 class pointer_to_binary_function 00450 : public binary_function<_Arg1, _Arg2, _Result> 00451 { 00452 protected: 00453 _Result (*_M_ptr)(_Arg1, _Arg2); 00454 00455 public: 00456 pointer_to_binary_function() { } 00457 00458 explicit 00459 pointer_to_binary_function(_Result (*__x)(_Arg1, _Arg2)) 00460 : _M_ptr(__x) { } 00461 00462 _Result 00463 operator()(_Arg1 __x, _Arg2 __y) const 00464 { return _M_ptr(__x, __y); } 00465 }; 00466 00467 /// One of the @link pointer_adaptors adaptors for function pointers@endlink. 00468 template<typename _Arg1, typename _Arg2, typename _Result> 00469 inline pointer_to_binary_function<_Arg1, _Arg2, _Result> 00470 ptr_fun(_Result (*__x)(_Arg1, _Arg2)) 00471 { return pointer_to_binary_function<_Arg1, _Arg2, _Result>(__x); } 00472 /** @} */ 00473 00474 template<typename _Tp> 00475 struct _Identity 00476 #ifndef __GXX_EXPERIMENTAL_CXX0X__ 00477 // unary_function itself is deprecated in C++11 and deriving from 00478 // it can even be a nuisance (see PR 52942). 00479 : public unary_function<_Tp,_Tp> 00480 #endif 00481 { 00482 _Tp& 00483 operator()(_Tp& __x) const 00484 { return __x; } 00485 00486 const _Tp& 00487 operator()(const _Tp& __x) const 00488 { return __x; } 00489 }; 00490 00491 template<typename _Pair> 00492 struct _Select1st 00493 #ifndef __GXX_EXPERIMENTAL_CXX0X__ 00494 : public unary_function<_Pair, typename _Pair::first_type> 00495 #endif 00496 { 00497 typename _Pair::first_type& 00498 operator()(_Pair& __x) const 00499 { return __x.first; } 00500 00501 const typename _Pair::first_type& 00502 operator()(const _Pair& __x) const 00503 { return __x.first; } 00504 00505 #ifdef __GXX_EXPERIMENTAL_CXX0X__ 00506 template<typename _Pair2> 00507 typename _Pair2::first_type& 00508 operator()(_Pair2& __x) const 00509 { return __x.first; } 00510 00511 template<typename _Pair2> 00512 const typename _Pair2::first_type& 00513 operator()(const _Pair2& __x) const 00514 { return __x.first; } 00515 #endif 00516 }; 00517 00518 template<typename _Pair> 00519 struct _Select2nd 00520 #ifndef __GXX_EXPERIMENTAL_CXX0X__ 00521 : public unary_function<_Pair, typename _Pair::second_type> 00522 #endif 00523 { 00524 typename _Pair::second_type& 00525 operator()(_Pair& __x) const 00526 { return __x.second; } 00527 00528 const typename _Pair::second_type& 00529 operator()(const _Pair& __x) const 00530 { return __x.second; } 00531 }; 00532 00533 // 20.3.8 adaptors pointers members 00534 /** @defgroup memory_adaptors Adaptors for pointers to members 00535 * @ingroup functors 00536 * 00537 * There are a total of 8 = 2^3 function objects in this family. 00538 * (1) Member functions taking no arguments vs member functions taking 00539 * one argument. 00540 * (2) Call through pointer vs call through reference. 00541 * (3) Const vs non-const member function. 00542 * 00543 * All of this complexity is in the function objects themselves. You can 00544 * ignore it by using the helper function mem_fun and mem_fun_ref, 00545 * which create whichever type of adaptor is appropriate. 00546 * 00547 * @{ 00548 */ 00549 /// One of the @link memory_adaptors adaptors for member 00550 /// pointers@endlink. 00551 template<typename _Ret, typename _Tp> 00552 class mem_fun_t : public unary_function<_Tp*, _Ret> 00553 { 00554 public: 00555 explicit 00556 mem_fun_t(_Ret (_Tp::*__pf)()) 00557 : _M_f(__pf) { } 00558 00559 _Ret 00560 operator()(_Tp* __p) const 00561 { return (__p->*_M_f)(); } 00562 00563 private: 00564 _Ret (_Tp::*_M_f)(); 00565 }; 00566 00567 /// One of the @link memory_adaptors adaptors for member 00568 /// pointers@endlink. 00569 template<typename _Ret, typename _Tp> 00570 class const_mem_fun_t : public unary_function<const _Tp*, _Ret> 00571 { 00572 public: 00573 explicit 00574 const_mem_fun_t(_Ret (_Tp::*__pf)() const) 00575 : _M_f(__pf) { } 00576 00577 _Ret 00578 operator()(const _Tp* __p) const 00579 { return (__p->*_M_f)(); } 00580 00581 private: 00582 _Ret (_Tp::*_M_f)() const; 00583 }; 00584 00585 /// One of the @link memory_adaptors adaptors for member 00586 /// pointers@endlink. 00587 template<typename _Ret, typename _Tp> 00588 class mem_fun_ref_t : public unary_function<_Tp, _Ret> 00589 { 00590 public: 00591 explicit 00592 mem_fun_ref_t(_Ret (_Tp::*__pf)()) 00593 : _M_f(__pf) { } 00594 00595 _Ret 00596 operator()(_Tp& __r) const 00597 { return (__r.*_M_f)(); } 00598 00599 private: 00600 _Ret (_Tp::*_M_f)(); 00601 }; 00602 00603 /// One of the @link memory_adaptors adaptors for member 00604 /// pointers@endlink. 00605 template<typename _Ret, typename _Tp> 00606 class const_mem_fun_ref_t : public unary_function<_Tp, _Ret> 00607 { 00608 public: 00609 explicit 00610 const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const) 00611 : _M_f(__pf) { } 00612 00613 _Ret 00614 operator()(const _Tp& __r) const 00615 { return (__r.*_M_f)(); } 00616 00617 private: 00618 _Ret (_Tp::*_M_f)() const; 00619 }; 00620 00621 /// One of the @link memory_adaptors adaptors for member 00622 /// pointers@endlink. 00623 template<typename _Ret, typename _Tp, typename _Arg> 00624 class mem_fun1_t : public binary_function<_Tp*, _Arg, _Ret> 00625 { 00626 public: 00627 explicit 00628 mem_fun1_t(_Ret (_Tp::*__pf)(_Arg)) 00629 : _M_f(__pf) { } 00630 00631 _Ret 00632 operator()(_Tp* __p, _Arg __x) const 00633 { return (__p->*_M_f)(__x); } 00634 00635 private: 00636 _Ret (_Tp::*_M_f)(_Arg); 00637 }; 00638 00639 /// One of the @link memory_adaptors adaptors for member 00640 /// pointers@endlink. 00641 template<typename _Ret, typename _Tp, typename _Arg> 00642 class const_mem_fun1_t : public binary_function<const _Tp*, _Arg, _Ret> 00643 { 00644 public: 00645 explicit 00646 const_mem_fun1_t(_Ret (_Tp::*__pf)(_Arg) const) 00647 : _M_f(__pf) { } 00648 00649 _Ret 00650 operator()(const _Tp* __p, _Arg __x) const 00651 { return (__p->*_M_f)(__x); } 00652 00653 private: 00654 _Ret (_Tp::*_M_f)(_Arg) const; 00655 }; 00656 00657 /// One of the @link memory_adaptors adaptors for member 00658 /// pointers@endlink. 00659 template<typename _Ret, typename _Tp, typename _Arg> 00660 class mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret> 00661 { 00662 public: 00663 explicit 00664 mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg)) 00665 : _M_f(__pf) { } 00666 00667 _Ret 00668 operator()(_Tp& __r, _Arg __x) const 00669 { return (__r.*_M_f)(__x); } 00670 00671 private: 00672 _Ret (_Tp::*_M_f)(_Arg); 00673 }; 00674 00675 /// One of the @link memory_adaptors adaptors for member 00676 /// pointers@endlink. 00677 template<typename _Ret, typename _Tp, typename _Arg> 00678 class const_mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret> 00679 { 00680 public: 00681 explicit 00682 const_mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg) const) 00683 : _M_f(__pf) { } 00684 00685 _Ret 00686 operator()(const _Tp& __r, _Arg __x) const 00687 { return (__r.*_M_f)(__x); } 00688 00689 private: 00690 _Ret (_Tp::*_M_f)(_Arg) const; 00691 }; 00692 00693 // Mem_fun adaptor helper functions. There are only two: 00694 // mem_fun and mem_fun_ref. 00695 template<typename _Ret, typename _Tp> 00696 inline mem_fun_t<_Ret, _Tp> 00697 mem_fun(_Ret (_Tp::*__f)()) 00698 { return mem_fun_t<_Ret, _Tp>(__f); } 00699 00700 template<typename _Ret, typename _Tp> 00701 inline const_mem_fun_t<_Ret, _Tp> 00702 mem_fun(_Ret (_Tp::*__f)() const) 00703 { return const_mem_fun_t<_Ret, _Tp>(__f); } 00704 00705 template<typename _Ret, typename _Tp> 00706 inline mem_fun_ref_t<_Ret, _Tp> 00707 mem_fun_ref(_Ret (_Tp::*__f)()) 00708 { return mem_fun_ref_t<_Ret, _Tp>(__f); } 00709 00710 template<typename _Ret, typename _Tp> 00711 inline const_mem_fun_ref_t<_Ret, _Tp> 00712 mem_fun_ref(_Ret (_Tp::*__f)() const) 00713 { return const_mem_fun_ref_t<_Ret, _Tp>(__f); } 00714 00715 template<typename _Ret, typename _Tp, typename _Arg> 00716 inline mem_fun1_t<_Ret, _Tp, _Arg> 00717 mem_fun(_Ret (_Tp::*__f)(_Arg)) 00718 { return mem_fun1_t<_Ret, _Tp, _Arg>(__f); } 00719 00720 template<typename _Ret, typename _Tp, typename _Arg> 00721 inline const_mem_fun1_t<_Ret, _Tp, _Arg> 00722 mem_fun(_Ret (_Tp::*__f)(_Arg) const) 00723 { return const_mem_fun1_t<_Ret, _Tp, _Arg>(__f); } 00724 00725 template<typename _Ret, typename _Tp, typename _Arg> 00726 inline mem_fun1_ref_t<_Ret, _Tp, _Arg> 00727 mem_fun_ref(_Ret (_Tp::*__f)(_Arg)) 00728 { return mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); } 00729 00730 template<typename _Ret, typename _Tp, typename _Arg> 00731 inline const_mem_fun1_ref_t<_Ret, _Tp, _Arg> 00732 mem_fun_ref(_Ret (_Tp::*__f)(_Arg) const) 00733 { return const_mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); } 00734 00735 /** @} */ 00736 00737 _GLIBCXX_END_NAMESPACE_VERSION 00738 } // namespace 00739 00740 #if !defined(__GXX_EXPERIMENTAL_CXX0X__) || _GLIBCXX_USE_DEPRECATED 00741 # include <backward/binders.h> 00742 #endif 00743 00744 #endif /* _STL_FUNCTION_H */