# stl_function.h

Go to the documentation of this file.

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