# stl_function.h

Go to the documentation of this file.

    00001 // Functor implementations -*- C++ -*-
    00002
    00003 // Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc.
    00004 //
    00005 // This file is part of the GNU ISO C++ Library.  This library is free
    00006 // software; you can redistribute it and/or modify it under the
    00007 // terms of the GNU General Public License as published by the
    00008 // Free Software Foundation; either version 2, or (at your option)
    00009 // any later version.
    00010
    00011 // This library is distributed in the hope that it will be useful,
    00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00014 // GNU General Public License for more details.
    00015
    00016 // You should have received a copy of the GNU General Public License along
    00017 // with this library; see the file COPYING.  If not, write to the Free
    00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
    00019 // USA.
    00020
    00021 // As a special exception, you may use this file as part of a free software
    00022 // library without restriction.  Specifically, if other files instantiate
    00023 // templates or use macros or inline functions from this file, or you compile
    00024 // this file and link it with other files to produce an executable, this
    00025 // file does not by itself cause the resulting executable to be covered by
    00026 // the GNU General Public License.  This exception does not however
    00027 // invalidate any other reasons why the executable file might be covered by
    00028 // the GNU General Public License.
    00029
    00030 /*
    00031  *
    00032  * Copyright (c) 1994
    00033  * Hewlett-Packard Company
    00034  *
    00035  * Permission to use, copy, modify, distribute and sell this software
    00036  * and its documentation for any purpose is hereby granted without fee,
    00037  * provided that the above copyright notice appear in all copies and
    00038  * that both that copyright notice and this permission notice appear
    00039  * in supporting documentation.  Hewlett-Packard Company makes no
    00040  * representations about the suitability of this software for any
    00041  * purpose.  It is provided "as is" without express or implied warranty.
    00042  *
    00043  *
    00044  * Copyright (c) 1996-1998
    00045  * Silicon Graphics Computer Systems, Inc.
    00046  *
    00047  * Permission to use, copy, modify, distribute and sell this software
    00048  * and its documentation for any purpose is hereby granted without fee,
    00049  * provided that the above copyright notice appear in all copies and
    00050  * that both that copyright notice and this permission notice appear
    00051  * in supporting documentation.  Silicon Graphics makes no
    00052  * representations about the suitability of this software for any
    00053  * purpose.  It is provided "as is" without express or implied warranty.
    00054  */
    00055
    00056 /** @file stl_function.h
    00057  *  This is an internal header file, included by other library headers.
    00058  *  You should not attempt to use it directly.
    00059  */
    00060
    00061 #ifndef _FUNCTION_H
    00062 #define _FUNCTION_H 1
    00063
    00064 namespace std
    00065 {
    00066   // 20.3.1 base classes
    00067   /** @defgroup s20_3_1_base Functor Base Classes
    00068    *  Function objects, or @e functors, are objects with an @c operator()
    00069    *  defined and accessible.  They can be passed as arguments to algorithm
    00070    *  templates and used in place of a function pointer.  Not only is the
    00071    *  resulting expressiveness of the library increased, but the generated
    00072    *  code can be more efficient than what you might write by hand.  When we
    00073    *  refer to "functors," then, generally we include function pointers in
    00074    *  the description as well.
    00075    *
    00076    *  Often, functors are only created as temporaries passed to algorithm
    00077    *  calls, rather than being created as named variables.
    00078    *
    00079    *  Two examples taken from the standard itself follow.  To perform a
    00080    *  by-element addition of two vectors @c a and @c b containing @c double,
    00081    *  and put the result in @c a, use
    00082    *  \code
    00083    *  transform (a.begin(), a.end(), b.begin(), a.begin(), plus<double>());
    00084    *  \endcode
    00085    *  To negate every element in @c a, use
    00086    *  \code
    00087    *  transform(a.begin(), a.end(), a.begin(), negate<double>());
    00088    *  \endcode
    00089    *  The addition and negation functions will be inlined directly.
    00090    *
    00091    *  The standard functiors are derived from structs named @c unary_function
    00092    *  and @c binary_function.  These two classes contain nothing but typedefs,
    00093    *  to aid in generic (template) programming.  If you write your own
    00094    *  functors, you might consider doing the same.
    00095    *
    00096    *  @{
    00097    */
    00098   /**
    00099    *  This is one of the @link s20_3_1_base functor base classes@endlink.
    00100    */
    00101   template <class _Arg, class _Result>
    00102     struct unary_function
    00103     {
    00104       typedef _Arg argument_type;   ///< @c argument_type is the type of the
    00105                                     ///     argument (no surprises here)
    00106
    00107       typedef _Result result_type;  ///< @c result_type is the return type
    00108     };
    00109
    00110   /**
    00111    *  This is one of the @link s20_3_1_base functor base classes@endlink.
    00112    */
    00113   template <class _Arg1, class _Arg2, class _Result>
    00114     struct binary_function
    00115     {
    00116       typedef _Arg1 first_argument_type;   ///< the type of the first argument
    00117                                            ///  (no surprises here)
    00118
    00119       typedef _Arg2 second_argument_type;  ///< the type of the second argument
    00120       typedef _Result result_type;         ///< type of the return type
    00121     };
    00122   /** @}  */
    00123
    00124   // 20.3.2 arithmetic
    00125   /** @defgroup s20_3_2_arithmetic Arithmetic Classes
    00126    *  Because basic math often needs to be done during an algorithm, the library
    00127    *  provides functors for those operations.  See the documentation for
    00128    *  @link s20_3_1_base the base classes@endlink for examples of their use.
    00129    *
    00130    *  @{
    00131    */
    00132   /// One of the @link s20_3_2_arithmetic math functors@endlink.
    00133   template <class _Tp>
    00134     struct plus : public binary_function<_Tp, _Tp, _Tp>
    00135     {
    00136       _Tp
    00137       operator()(const _Tp& __x, const _Tp& __y) const
    00138       { return __x + __y; }
    00139     };
    00140
    00141   /// One of the @link s20_3_2_arithmetic math functors@endlink.
    00142   template <class _Tp>
    00143     struct minus : public binary_function<_Tp, _Tp, _Tp>
    00144     {
    00145       _Tp
    00146       operator()(const _Tp& __x, const _Tp& __y) const
    00147       { return __x - __y; }
    00148     };
    00149
    00150   /// One of the @link s20_3_2_arithmetic math functors@endlink.
    00151   template <class _Tp>
    00152     struct multiplies : public binary_function<_Tp, _Tp, _Tp>
    00153     {
    00154       _Tp
    00155       operator()(const _Tp& __x, const _Tp& __y) const
    00156       { return __x * __y; }
    00157     };
    00158
    00159   /// One of the @link s20_3_2_arithmetic math functors@endlink.
    00160   template <class _Tp>
    00161     struct divides : public binary_function<_Tp, _Tp, _Tp>
    00162     {
    00163       _Tp
    00164       operator()(const _Tp& __x, const _Tp& __y) const
    00165       { return __x / __y; }
    00166     };
    00167
    00168   /// One of the @link s20_3_2_arithmetic math functors@endlink.
    00169   template <class _Tp>
    00170     struct modulus : public binary_function<_Tp, _Tp, _Tp>
    00171     {
    00172       _Tp
    00173       operator()(const _Tp& __x, const _Tp& __y) const
    00174       { return __x % __y; }
    00175     };
    00176
    00177   /// One of the @link s20_3_2_arithmetic math functors@endlink.
    00178   template <class _Tp>
    00179     struct negate : public unary_function<_Tp, _Tp>
    00180     {
    00181       _Tp
    00182       operator()(const _Tp& __x) const
    00183       { return -__x; }
    00184     };
    00185   /** @}  */
    00186
    00187   // 20.3.3 comparisons
    00188   /** @defgroup s20_3_3_comparisons Comparison Classes
    00189    *  The library provides six wrapper functors for all the basic comparisons
    00190    *  in C++, like @c <.
    00191    *
    00192    *  @{
    00193    */
    00194   /// One of the @link s20_3_3_comparisons comparison functors@endlink.
    00195   template <class _Tp>
    00196     struct equal_to : public binary_function<_Tp, _Tp, bool>
    00197     {
    00198       bool
    00199       operator()(const _Tp& __x, const _Tp& __y) const
    00200       { return __x == __y; }
    00201     };
    00202
    00203   /// One of the @link s20_3_3_comparisons comparison functors@endlink.
    00204   template <class _Tp>
    00205     struct not_equal_to : public binary_function<_Tp, _Tp, bool>
    00206     {
    00207       bool
    00208       operator()(const _Tp& __x, const _Tp& __y) const
    00209       { return __x != __y; }
    00210     };
    00211
    00212   /// One of the @link s20_3_3_comparisons comparison functors@endlink.
    00213   template <class _Tp>
    00214     struct greater : public binary_function<_Tp, _Tp, bool>
    00215     {
    00216       bool
    00217       operator()(const _Tp& __x, const _Tp& __y) const
    00218       { return __x > __y; }
    00219     };
    00220
    00221   /// One of the @link s20_3_3_comparisons comparison functors@endlink.
    00222   template <class _Tp>
    00223     struct less : public binary_function<_Tp, _Tp, bool>
    00224     {
    00225       bool
    00226       operator()(const _Tp& __x, const _Tp& __y) const
    00227       { return __x < __y; }
    00228     };
    00229
    00230   /// One of the @link s20_3_3_comparisons comparison functors@endlink.
    00231   template <class _Tp>
    00232     struct greater_equal : public binary_function<_Tp, _Tp, bool>
    00233     {
    00234       bool
    00235       operator()(const _Tp& __x, const _Tp& __y) const
    00236       { return __x >= __y; }
    00237     };
    00238
    00239   /// One of the @link s20_3_3_comparisons comparison functors@endlink.
    00240   template <class _Tp>
    00241     struct less_equal : public binary_function<_Tp, _Tp, bool>
    00242     {
    00243       bool
    00244       operator()(const _Tp& __x, const _Tp& __y) const
    00245       { return __x <= __y; }
    00246     };
    00247   /** @}  */
    00248
    00249   // 20.3.4 logical operations
    00250   /** @defgroup s20_3_4_logical Boolean Operations Classes
    00251    *  Here are wrapper functors for Boolean operations:  @c &&, @c ||, and @c !.
    00252    *
    00253    *  @{
    00254    */
    00255   /// One of the @link s20_3_4_logical Boolean operations functors@endlink.
    00256   template <class _Tp>
    00257     struct logical_and : public binary_function<_Tp, _Tp, bool>
    00258     {
    00259       bool
    00260       operator()(const _Tp& __x, const _Tp& __y) const
    00261       { return __x && __y; }
    00262     };
    00263
    00264   /// One of the @link s20_3_4_logical Boolean operations functors@endlink.
    00265   template <class _Tp>
    00266     struct logical_or : public binary_function<_Tp, _Tp, bool>
    00267     {
    00268       bool
    00269       operator()(const _Tp& __x, const _Tp& __y) const
    00270       { return __x || __y; }
    00271     };
    00272
    00273   /// One of the @link s20_3_4_logical Boolean operations functors@endlink.
    00274   template <class _Tp>
    00275     struct logical_not : public unary_function<_Tp, bool>
    00276     {
    00277       bool
    00278       operator()(const _Tp& __x) const
    00279       { return !__x; }
    00280     };
    00281   /** @}  */
    00282
    00283   // 20.3.5 negators
    00284   /** @defgroup s20_3_5_negators Negators
    00285    *  The functions @c not1 and @c not2 each take a predicate functor
    00286    *  and return an instance of @c unary_negate or
    00287    *  @c binary_negate, respectively.  These classes are functors whose
    00288    *  @c operator() performs the stored predicate function and then returns
    00289    *  the negation of the result.
    00290    *
    00291    *  For example, given a vector of integers and a trivial predicate,
    00292    *  \code
    00293    *  struct IntGreaterThanThree
    00294    *    : public std::unary_function<int, bool>
    00295    *  {
    00296    *      bool operator() (int x) { return x > 3; }
    00297    *  };
    00298    *
    00299    *  std::find_if (v.begin(), v.end(), not1(IntGreaterThanThree()));
    00300    *  \endcode
    00301    *  The call to @c find_if will locate the first index (i) of @c v for which
    00302    *  "!(v[i] > 3)" is true.
    00303    *
    00304    *  The not1/unary_negate combination works on predicates taking a single
    00305    *  argument.  The not2/binary_negate combination works on predicates which
    00306    *  take two arguments.
    00307    *
    00308    *  @{
    00309    */
    00310   /// One of the @link s20_3_5_negators negation functors@endlink.
    00311   template <class _Predicate>
    00312     class unary_negate
    00313     : public unary_function<typename _Predicate::argument_type, bool>
    00314     {
    00315     protected:
    00316       _Predicate _M_pred;
    00317     public:
    00318       explicit
    00319       unary_negate(const _Predicate& __x) : _M_pred(__x) {}
    00320
    00321       bool
    00322       operator()(const typename _Predicate::argument_type& __x) const
    00323       { return !_M_pred(__x); }
    00324     };
    00325
    00326   /// One of the @link s20_3_5_negators negation functors@endlink.
    00327   template <class _Predicate>
    00328     inline unary_negate<_Predicate>
    00329     not1(const _Predicate& __pred)
    00330     { return unary_negate<_Predicate>(__pred); }
    00331
    00332   /// One of the @link s20_3_5_negators negation functors@endlink.
    00333   template <class _Predicate>
    00334     class binary_negate
    00335     : public binary_function<typename _Predicate::first_argument_type,
    00336                  typename _Predicate::second_argument_type,
    00337                  bool>
    00338     {
    00339     protected:
    00340       _Predicate _M_pred;
    00341     public:
    00342       explicit
    00343       binary_negate(const _Predicate& __x)
    00344       : _M_pred(__x) { }
    00345
    00346       bool
    00347       operator()(const typename _Predicate::first_argument_type& __x,
    00348          const typename _Predicate::second_argument_type& __y) const
    00349       { return !_M_pred(__x, __y); }
    00350     };
    00351
    00352   /// One of the @link s20_3_5_negators negation functors@endlink.
    00353   template <class _Predicate>
    00354     inline binary_negate<_Predicate>
    00355     not2(const _Predicate& __pred)
    00356     { return binary_negate<_Predicate>(__pred); }
    00357   /** @}  */
    00358
    00359   // 20.3.6 binders
    00360   /** @defgroup s20_3_6_binder Binder Classes
    00361    *  Binders turn functions/functors with two arguments into functors with
    00362    *  a single argument, storing an argument to be applied later.  For
    00363    *  example, an variable @c B of type @c binder1st is constructed from a
    00364    *  functor @c f and an argument @c x.  Later, B's @c operator() is called
    00365    *  with a single argument @c y.  The return value is the value of @c f(x,y).
    00366    *  @c B can be "called" with various arguments (y1, y2, ...) and will in
    00367    *  turn call @c f(x,y1), @c f(x,y2), ...
    00368    *
    00369    *  The function @c bind1st is provided to save some typing.  It takes the
    00370    *  function and an argument as parameters, and returns an instance of
    00371    *  @c binder1st.
    00372    *
    00373    *  The type @c binder2nd and its creator function @c bind2nd do the same
    00374    *  thing, but the stored argument is passed as the second parameter instead
    00375    *  of the first, e.g., @c bind2nd(std::minus<float>,1.3) will create a
    00376    *  functor whose @c operator() accepts a floating-point number, subtracts
    00377    *  1.3 from it, and returns the result.  (If @c bind1st had been used,
    00378    *  the functor would perform "1.3 - x" instead.
    00379    *
    00380    *  Creator-wrapper functions like @c bind1st are intended to be used in
    00381    *  calling algorithms.  Their return values will be temporary objects.
    00382    *  (The goal is to not require you to type names like
    00383    *  @c std::binder1st<std::plus<int>> for declaring a variable to hold the
    00384    *  return value from @c bind1st(std::plus<int>,5).
    00385    *
    00386    *  These become more useful when combined with the composition functions.
    00387    *
    00388    *  @{
    00389    */
    00390   /// One of the @link s20_3_6_binder binder functors@endlink.
    00391   template <class _Operation>
    00392     class binder1st
    00393     : public unary_function<typename _Operation::second_argument_type,
    00394                 typename _Operation::result_type>
    00395     {
    00396     protected:
    00397       _Operation op;
    00398       typename _Operation::first_argument_type value;
    00399     public:
    00400       binder1st(const _Operation& __x,
    00401         const typename _Operation::first_argument_type& __y)
    00402       : op(__x), value(__y) {}
    00403
    00404       typename _Operation::result_type
    00405       operator()(const typename _Operation::second_argument_type& __x) const
    00406       { return op(value, __x); }
    00407
    00408       // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00409       // 109.  Missing binders for non-const sequence elements
    00410       typename _Operation::result_type
    00411       operator()(typename _Operation::second_argument_type& __x) const
    00412       { return op(value, __x); }
    00413     };
    00414
    00415   /// One of the @link s20_3_6_binder binder functors@endlink.
    00416   template <class _Operation, class _Tp>
    00417     inline binder1st<_Operation>
    00418     bind1st(const _Operation& __fn, const _Tp& __x)
    00419     {
    00420       typedef typename _Operation::first_argument_type _Arg1_type;
    00421       return binder1st<_Operation>(__fn, _Arg1_type(__x));
    00422     }
    00423
    00424   /// One of the @link s20_3_6_binder binder functors@endlink.
    00425   template <class _Operation>
    00426     class binder2nd
    00427     : public unary_function<typename _Operation::first_argument_type,
    00428                 typename _Operation::result_type>
    00429     {
    00430     protected:
    00431       _Operation op;
    00432       typename _Operation::second_argument_type value;
    00433     public:
    00434       binder2nd(const _Operation& __x,
    00435         const typename _Operation::second_argument_type& __y)
    00436       : op(__x), value(__y) {}
    00437
    00438       typename _Operation::result_type
    00439       operator()(const typename _Operation::first_argument_type& __x) const
    00440       { return op(__x, value); }
    00441
    00442       // _GLIBCXX_RESOLVE_LIB_DEFECTS
    00443       // 109.  Missing binders for non-const sequence elements
    00444       typename _Operation::result_type
    00445       operator()(typename _Operation::first_argument_type& __x) const
    00446       { return op(__x, value); }
    00447     };
    00448
    00449   /// One of the @link s20_3_6_binder binder functors@endlink.
    00450   template <class _Operation, class _Tp>
    00451     inline binder2nd<_Operation>
    00452     bind2nd(const _Operation& __fn, const _Tp& __x)
    00453     {
    00454       typedef typename _Operation::second_argument_type _Arg2_type;
    00455       return binder2nd<_Operation>(__fn, _Arg2_type(__x));
    00456     }
    00457   /** @}  */
    00458
    00459   // 20.3.7 adaptors pointers functions
    00460   /** @defgroup s20_3_7_adaptors Adaptors for pointers to functions
    00461    *  The advantage of function objects over pointers to functions is that
    00462    *  the objects in the standard library declare nested typedefs describing
    00463    *  their argument and result types with uniform names (e.g., @c result_type
    00464    *  from the base classes @c unary_function and @c binary_function).
    00465    *  Sometimes those typedefs are required, not just optional.
    00466    *
    00467    *  Adaptors are provided to turn pointers to unary (single-argument) and
    00468    *  binary (double-argument) functions into function objects.  The
    00469    *  long-winded functor @c pointer_to_unary_function is constructed with a
    00470    *  function pointer @c f, and its @c operator() called with argument @c x
    00471    *  returns @c f(x).  The functor @c pointer_to_binary_function does the same
    00472    *  thing, but with a double-argument @c f and @c operator().
    00473    *
    00474    *  The function @c ptr_fun takes a pointer-to-function @c f and constructs
    00475    *  an instance of the appropriate functor.
    00476    *
    00477    *  @{
    00478    */
    00479   /// One of the @link s20_3_7_adaptors adaptors for function pointers@endlink.
    00480   template <class _Arg, class _Result>
    00481     class pointer_to_unary_function : public unary_function<_Arg, _Result>
    00482     {
    00483     protected:
    00484       _Result (*_M_ptr)(_Arg);
    00485     public:
    00486       pointer_to_unary_function() {}
    00487
    00488       explicit
    00489       pointer_to_unary_function(_Result (*__x)(_Arg))
    00490       : _M_ptr(__x) {}
    00491
    00492       _Result
    00493       operator()(_Arg __x) const
    00494       { return _M_ptr(__x); }
    00495     };
    00496
    00497   /// One of the @link s20_3_7_adaptors adaptors for function pointers@endlink.
    00498   template <class _Arg, class _Result>
    00499     inline pointer_to_unary_function<_Arg, _Result>
    00500     ptr_fun(_Result (*__x)(_Arg))
    00501     { return pointer_to_unary_function<_Arg, _Result>(__x); }
    00502
    00503   /// One of the @link s20_3_7_adaptors adaptors for function pointers@endlink.
    00504   template <class _Arg1, class _Arg2, class _Result>
    00505     class pointer_to_binary_function
    00506     : public binary_function<_Arg1, _Arg2, _Result>
    00507     {
    00508     protected:
    00509       _Result (*_M_ptr)(_Arg1, _Arg2);
    00510     public:
    00511       pointer_to_binary_function() {}
    00512
    00513       explicit
    00514       pointer_to_binary_function(_Result (*__x)(_Arg1, _Arg2))
    00515       : _M_ptr(__x) {}
    00516
    00517       _Result
    00518       operator()(_Arg1 __x, _Arg2 __y) const
    00519       { return _M_ptr(__x, __y); }
    00520     };
    00521
    00522   /// One of the @link s20_3_7_adaptors adaptors for function pointers@endlink.
    00523   template <class _Arg1, class _Arg2, class _Result>
    00524     inline pointer_to_binary_function<_Arg1, _Arg2, _Result>
    00525     ptr_fun(_Result (*__x)(_Arg1, _Arg2))
    00526     { return pointer_to_binary_function<_Arg1, _Arg2, _Result>(__x); }
    00527   /** @}  */
    00528
    00529   template <class _Tp>
    00530     struct _Identity : public unary_function<_Tp,_Tp>
    00531     {
    00532       _Tp&
    00533       operator()(_Tp& __x) const
    00534       { return __x; }
    00535
    00536       const _Tp&
    00537       operator()(const _Tp& __x) const
    00538       { return __x; }
    00539     };
    00540
    00541   template <class _Pair>
    00542     struct _Select1st : public unary_function<_Pair,
    00543                           typename _Pair::first_type>
    00544     {
    00545       typename _Pair::first_type&
    00546       operator()(_Pair& __x) const
    00547       { return __x.first; }
    00548
    00549       const typename _Pair::first_type&
    00550       operator()(const _Pair& __x) const
    00551       { return __x.first; }
    00552     };
    00553
    00554   template <class _Pair>
    00555     struct _Select2nd : public unary_function<_Pair,
    00556                           typename _Pair::second_type>
    00557     {
    00558       typename _Pair::second_type&
    00559       operator()(_Pair& __x) const
    00560       { return __x.second; }
    00561
    00562       const typename _Pair::second_type&
    00563       operator()(const _Pair& __x) const
    00564       { return __x.second; }
    00565     };
    00566
    00567   // 20.3.8 adaptors pointers members
    00568   /** @defgroup s20_3_8_memadaptors Adaptors for pointers to members
    00569    *  There are a total of 16 = 2^4 function objects in this family.
    00570    *   (1) Member functions taking no arguments vs member functions taking
    00571    *        one argument.
    00572    *   (2) Call through pointer vs call through reference.
    00573    *   (3) Member function with void return type vs member function with
    00574    *       non-void return type.
    00575    *   (4) Const vs non-const member function.
    00576    *
    00577    *  Note that choice (3) is nothing more than a workaround: according
    00578    *   to the draft, compilers should handle void and non-void the same way.
    00579    *   This feature is not yet widely implemented, though.  You can only use
    00580    *   member functions returning void if your compiler supports partial
    00581    *   specialization.
    00582    *
    00583    *  All of this complexity is in the function objects themselves.  You can
    00584    *   ignore it by using the helper function mem_fun and mem_fun_ref,
    00585    *   which create whichever type of adaptor is appropriate.
    00586    *
    00587    *  @{
    00588    */
    00589   /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
    00590   template <class _Ret, class _Tp>
    00591     class mem_fun_t : public unary_function<_Tp*, _Ret>
    00592     {
    00593     public:
    00594       explicit
    00595       mem_fun_t(_Ret (_Tp::*__pf)())
    00596       : _M_f(__pf) {}
    00597
    00598       _Ret
    00599       operator()(_Tp* __p) const
    00600       { return (__p->*_M_f)(); }
    00601     private:
    00602       _Ret (_Tp::*_M_f)();
    00603     };
    00604
    00605   /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
    00606   template <class _Ret, class _Tp>
    00607     class const_mem_fun_t : public unary_function<const _Tp*, _Ret>
    00608     {
    00609     public:
    00610       explicit
    00611       const_mem_fun_t(_Ret (_Tp::*__pf)() const)
    00612       : _M_f(__pf) {}
    00613
    00614       _Ret
    00615       operator()(const _Tp* __p) const
    00616       { return (__p->*_M_f)(); }
    00617     private:
    00618       _Ret (_Tp::*_M_f)() const;
    00619     };
    00620
    00621   /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
    00622   template <class _Ret, class _Tp>
    00623     class mem_fun_ref_t : public unary_function<_Tp, _Ret>
    00624     {
    00625     public:
    00626       explicit
    00627       mem_fun_ref_t(_Ret (_Tp::*__pf)())
    00628       : _M_f(__pf) {}
    00629
    00630       _Ret
    00631       operator()(_Tp& __r) const
    00632       { return (__r.*_M_f)(); }
    00633     private:
    00634       _Ret (_Tp::*_M_f)();
    00635   };
    00636
    00637   /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
    00638   template <class _Ret, class _Tp>
    00639     class const_mem_fun_ref_t : public unary_function<_Tp, _Ret>
    00640     {
    00641     public:
    00642       explicit
    00643       const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const)
    00644       : _M_f(__pf) {}
    00645
    00646       _Ret
    00647       operator()(const _Tp& __r) const
    00648       { return (__r.*_M_f)(); }
    00649     private:
    00650       _Ret (_Tp::*_M_f)() const;
    00651     };
    00652
    00653   /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
    00654   template <class _Ret, class _Tp, class _Arg>
    00655     class mem_fun1_t : public binary_function<_Tp*, _Arg, _Ret>
    00656     {
    00657     public:
    00658       explicit
    00659       mem_fun1_t(_Ret (_Tp::*__pf)(_Arg))
    00660       : _M_f(__pf) {}
    00661
    00662       _Ret
    00663       operator()(_Tp* __p, _Arg __x) const
    00664       { return (__p->*_M_f)(__x); }
    00665     private:
    00666       _Ret (_Tp::*_M_f)(_Arg);
    00667     };
    00668
    00669   /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
    00670   template <class _Ret, class _Tp, class _Arg>
    00671     class const_mem_fun1_t : public binary_function<const _Tp*, _Arg, _Ret>
    00672     {
    00673     public:
    00674       explicit
    00675       const_mem_fun1_t(_Ret (_Tp::*__pf)(_Arg) const)
    00676       : _M_f(__pf) {}
    00677
    00678       _Ret
    00679       operator()(const _Tp* __p, _Arg __x) const
    00680       { return (__p->*_M_f)(__x); }
    00681     private:
    00682       _Ret (_Tp::*_M_f)(_Arg) const;
    00683     };
    00684
    00685   /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
    00686   template <class _Ret, class _Tp, class _Arg>
    00687     class mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret>
    00688     {
    00689     public:
    00690       explicit
    00691       mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg))
    00692       : _M_f(__pf) {}
    00693
    00694       _Ret
    00695       operator()(_Tp& __r, _Arg __x) const
    00696       { return (__r.*_M_f)(__x); }
    00697     private:
    00698       _Ret (_Tp::*_M_f)(_Arg);
    00699     };
    00700
    00701   /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
    00702   template <class _Ret, class _Tp, class _Arg>
    00703     class const_mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret>
    00704     {
    00705     public:
    00706       explicit
    00707       const_mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg) const)
    00708       : _M_f(__pf) {}
    00709
    00710       _Ret
    00711       operator()(const _Tp& __r, _Arg __x) const
    00712       { return (__r.*_M_f)(__x); }
    00713     private:
    00714       _Ret (_Tp::*_M_f)(_Arg) const;
    00715     };
    00716
    00717   /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
    00718   template <class _Tp>
    00719     class mem_fun_t<void, _Tp> : public unary_function<_Tp*, void>
    00720     {
    00721     public:
    00722       explicit
    00723       mem_fun_t(void (_Tp::*__pf)())
    00724       : _M_f(__pf) {}
    00725
    00726       void
    00727       operator()(_Tp* __p) const
    00728       { (__p->*_M_f)(); }
    00729     private:
    00730       void (_Tp::*_M_f)();
    00731     };
    00732
    00733   /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
    00734   template <class _Tp>
    00735     class const_mem_fun_t<void, _Tp> : public unary_function<const _Tp*, void>
    00736     {
    00737     public:
    00738       explicit
    00739       const_mem_fun_t(void (_Tp::*__pf)() const)
    00740       : _M_f(__pf) {}
    00741
    00742       void
    00743       operator()(const _Tp* __p) const
    00744       { (__p->*_M_f)(); }
    00745     private:
    00746       void (_Tp::*_M_f)() const;
    00747     };
    00748
    00749   /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
    00750   template <class _Tp>
    00751     class mem_fun_ref_t<void, _Tp> : public unary_function<_Tp, void>
    00752     {
    00753     public:
    00754       explicit
    00755       mem_fun_ref_t(void (_Tp::*__pf)())
    00756       : _M_f(__pf) {}
    00757
    00758       void
    00759       operator()(_Tp& __r) const
    00760       { (__r.*_M_f)(); }
    00761     private:
    00762       void (_Tp::*_M_f)();
    00763     };
    00764
    00765   /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
    00766   template <class _Tp>
    00767     class const_mem_fun_ref_t<void, _Tp> : public unary_function<_Tp, void>
    00768     {
    00769     public:
    00770       explicit
    00771       const_mem_fun_ref_t(void (_Tp::*__pf)() const)
    00772       : _M_f(__pf) {}
    00773
    00774       void
    00775       operator()(const _Tp& __r) const
    00776       { (__r.*_M_f)(); }
    00777     private:
    00778       void (_Tp::*_M_f)() const;
    00779     };
    00780
    00781   /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
    00782   template <class _Tp, class _Arg>
    00783     class mem_fun1_t<void, _Tp, _Arg> : public binary_function<_Tp*, _Arg, void>
    00784     {
    00785     public:
    00786       explicit
    00787       mem_fun1_t(void (_Tp::*__pf)(_Arg))
    00788       : _M_f(__pf) {}
    00789
    00790       void
    00791       operator()(_Tp* __p, _Arg __x) const
    00792       { (__p->*_M_f)(__x); }
    00793     private:
    00794       void (_Tp::*_M_f)(_Arg);
    00795     };
    00796
    00797   /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
    00798   template <class _Tp, class _Arg>
    00799     class const_mem_fun1_t<void, _Tp, _Arg>
    00800     : public binary_function<const _Tp*, _Arg, void>
    00801     {
    00802     public:
    00803       explicit
    00804       const_mem_fun1_t(void (_Tp::*__pf)(_Arg) const)
    00805       : _M_f(__pf) {}
    00806
    00807       void
    00808       operator()(const _Tp* __p, _Arg __x) const
    00809       { (__p->*_M_f)(__x); }
    00810     private:
    00811       void (_Tp::*_M_f)(_Arg) const;
    00812     };
    00813
    00814   /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
    00815   template <class _Tp, class _Arg>
    00816     class mem_fun1_ref_t<void, _Tp, _Arg>
    00817     : public binary_function<_Tp, _Arg, void>
    00818     {
    00819     public:
    00820       explicit
    00821       mem_fun1_ref_t(void (_Tp::*__pf)(_Arg))
    00822       : _M_f(__pf) {}
    00823
    00824       void
    00825       operator()(_Tp& __r, _Arg __x) const
    00826       { (__r.*_M_f)(__x); }
    00827     private:
    00828       void (_Tp::*_M_f)(_Arg);
    00829     };
    00830
    00831   /// One of the @link s20_3_8_memadaptors adaptors for member pointers@endlink.
    00832   template <class _Tp, class _Arg>
    00833     class const_mem_fun1_ref_t<void, _Tp, _Arg>
    00834     : public binary_function<_Tp, _Arg, void>
    00835     {
    00836     public:
    00837       explicit
    00838       const_mem_fun1_ref_t(void (_Tp::*__pf)(_Arg) const)
    00839       : _M_f(__pf) {}
    00840
    00841       void
    00842       operator()(const _Tp& __r, _Arg __x) const
    00843       { (__r.*_M_f)(__x); }
    00844     private:
    00845       void (_Tp::*_M_f)(_Arg) const;
    00846     };
    00847
    00848   // Mem_fun adaptor helper functions.  There are only two:
    00849   // mem_fun and mem_fun_ref.
    00850   template <class _Ret, class _Tp>
    00851     inline mem_fun_t<_Ret, _Tp>
    00852     mem_fun(_Ret (_Tp::*__f)())
    00853     { return mem_fun_t<_Ret, _Tp>(__f); }
    00854
    00855   template <class _Ret, class _Tp>
    00856     inline const_mem_fun_t<_Ret, _Tp>
    00857     mem_fun(_Ret (_Tp::*__f)() const)
    00858     { return const_mem_fun_t<_Ret, _Tp>(__f); }
    00859
    00860   template <class _Ret, class _Tp>
    00861     inline mem_fun_ref_t<_Ret, _Tp>
    00862     mem_fun_ref(_Ret (_Tp::*__f)())
    00863     { return mem_fun_ref_t<_Ret, _Tp>(__f); }
    00864
    00865   template <class _Ret, class _Tp>
    00866     inline const_mem_fun_ref_t<_Ret, _Tp>
    00867     mem_fun_ref(_Ret (_Tp::*__f)() const)
    00868     { return const_mem_fun_ref_t<_Ret, _Tp>(__f); }
    00869
    00870   template <class _Ret, class _Tp, class _Arg>
    00871     inline mem_fun1_t<_Ret, _Tp, _Arg>
    00872     mem_fun(_Ret (_Tp::*__f)(_Arg))
    00873     { return mem_fun1_t<_Ret, _Tp, _Arg>(__f); }
    00874
    00875   template <class _Ret, class _Tp, class _Arg>
    00876     inline const_mem_fun1_t<_Ret, _Tp, _Arg>
    00877     mem_fun(_Ret (_Tp::*__f)(_Arg) const)
    00878     { return const_mem_fun1_t<_Ret, _Tp, _Arg>(__f); }
    00879
    00880   template <class _Ret, class _Tp, class _Arg>
    00881     inline mem_fun1_ref_t<_Ret, _Tp, _Arg>
    00882     mem_fun_ref(_Ret (_Tp::*__f)(_Arg))
    00883     { return mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); }
    00884
    00885   template <class _Ret, class _Tp, class _Arg>
    00886     inline const_mem_fun1_ref_t<_Ret, _Tp, _Arg>
    00887     mem_fun_ref(_Ret (_Tp::*__f)(_Arg) const)
    00888     { return const_mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); }
    00889
    00890   /** @}  */
    00891
    00892 } // namespace std
    00893
    00894 #endif /* _FUNCTION_H */
    00895
    00896 // Local Variables:
    00897 // mode:C++
    00898 // End: