home *** CD-ROM | disk | FTP | other *** search
/ Beginning C++ Through Gam…rogramming (2nd Edition) / BCGP2E.ISO / bloodshed / devcpp-4.9.9.2_setup.exe / stl_function.h < prev    next >
C/C++ Source or Header  |  2005-01-29  |  29KB  |  899 lines

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