stl_function.h

00001 /*
00002  *
00003  * Copyright (c) 1994
00004  * Hewlett-Packard Company
00005  *
00006  * Permission to use, copy, modify, distribute and sell this software
00007  * and its documentation for any purpose is hereby granted without fee,
00008  * provided that the above copyright notice appear in all copies and
00009  * that both that copyright notice and this permission notice appear
00010  * in supporting documentation.  Hewlett-Packard Company makes no
00011  * representations about the suitability of this software for any
00012  * purpose.  It is provided "as is" without express or implied warranty.
00013  *
00014  *
00015  * Copyright (c) 1996-1998
00016  * Silicon Graphics Computer Systems, Inc.
00017  *
00018  * Permission to use, copy, modify, distribute and sell this software
00019  * and its documentation for any purpose is hereby granted without fee,
00020  * provided that the above copyright notice appear in all copies and
00021  * that both that copyright notice and this permission notice appear
00022  * in supporting documentation.  Silicon Graphics makes no
00023  * representations about the suitability of this software for any
00024  * purpose.  It is provided "as is" without express or implied warranty.
00025  */
00026 
00027 /* NOTE: This is an internal header file, included by other STL headers.
00028  *   You should not attempt to use it directly.
00029  */
00030 
00031 #ifndef __SGI_STL_INTERNAL_FUNCTION_H
00032 #define __SGI_STL_INTERNAL_FUNCTION_H
00033 
00034 __STL_BEGIN_NAMESPACE
00035 
00036 template <class _Arg, class _Result>
00037 struct unary_function {
00038   typedef _Arg argument_type;
00039   typedef _Result result_type;
00040 };
00041 
00042 template <class _Arg1, class _Arg2, class _Result>
00043 struct binary_function {
00044   typedef _Arg1 first_argument_type;
00045   typedef _Arg2 second_argument_type;
00046   typedef _Result result_type;
00047 };      
00048 
00049 template <class _Tp>
00050 struct plus : public binary_function<_Tp,_Tp,_Tp> {
00051   _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x + __y; }
00052 };
00053 
00054 template <class _Tp>
00055 struct minus : public binary_function<_Tp,_Tp,_Tp> {
00056   _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x - __y; }
00057 };
00058 
00059 template <class _Tp>
00060 struct multiplies : public binary_function<_Tp,_Tp,_Tp> {
00061   _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x * __y; }
00062 };
00063 
00064 template <class _Tp>
00065 struct divides : public binary_function<_Tp,_Tp,_Tp> {
00066   _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x / __y; }
00067 };
00068 
00069 // identity_element (not part of the C++ standard).
00070 
00071 template <class _Tp> inline _Tp identity_element(plus<_Tp>) {
00072   return _Tp(0);
00073 }
00074 template <class _Tp> inline _Tp identity_element(multiplies<_Tp>) {
00075   return _Tp(1);
00076 }
00077 
00078 template <class _Tp>
00079 struct modulus : public binary_function<_Tp,_Tp,_Tp> 
00080 {
00081   _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x % __y; }
00082 };
00083 
00084 template <class _Tp>
00085 struct negate : public unary_function<_Tp,_Tp> 
00086 {
00087   _Tp operator()(const _Tp& __x) const { return -__x; }
00088 };
00089 
00090 template <class _Tp>
00091 struct equal_to : public binary_function<_Tp,_Tp,bool> 
00092 {
00093   bool operator()(const _Tp& __x, const _Tp& __y) const { return __x == __y; }
00094 };
00095 
00096 template <class _Tp>
00097 struct not_equal_to : public binary_function<_Tp,_Tp,bool> 
00098 {
00099   bool operator()(const _Tp& __x, const _Tp& __y) const { return __x != __y; }
00100 };
00101 
00102 template <class _Tp>
00103 struct greater : public binary_function<_Tp,_Tp,bool> 
00104 {
00105   bool operator()(const _Tp& __x, const _Tp& __y) const { return __x > __y; }
00106 };
00107 
00108 template <class _Tp>
00109 struct less : public binary_function<_Tp,_Tp,bool> 
00110 {
00111   bool operator()(const _Tp& __x, const _Tp& __y) const { return __x < __y; }
00112 };
00113 
00114 template <class _Tp>
00115 struct greater_equal : public binary_function<_Tp,_Tp,bool>
00116 {
00117   bool operator()(const _Tp& __x, const _Tp& __y) const { return __x >= __y; }
00118 };
00119 
00120 template <class _Tp>
00121 struct less_equal : public binary_function<_Tp,_Tp,bool> 
00122 {
00123   bool operator()(const _Tp& __x, const _Tp& __y) const { return __x <= __y; }
00124 };
00125 
00126 template <class _Tp>
00127 struct logical_and : public binary_function<_Tp,_Tp,bool>
00128 {
00129   bool operator()(const _Tp& __x, const _Tp& __y) const { return __x && __y; }
00130 };
00131 
00132 template <class _Tp>
00133 struct logical_or : public binary_function<_Tp,_Tp,bool>
00134 {
00135   bool operator()(const _Tp& __x, const _Tp& __y) const { return __x || __y; }
00136 };
00137 
00138 template <class _Tp>
00139 struct logical_not : public unary_function<_Tp,bool>
00140 {
00141   bool operator()(const _Tp& __x) const { return !__x; }
00142 };
00143 
00144 template <class _Predicate>
00145 class unary_negate
00146   : public unary_function<typename _Predicate::argument_type, bool> {
00147 protected:
00148   _Predicate _M_pred;
00149 public:
00150   explicit unary_negate(const _Predicate& __x) : _M_pred(__x) {}
00151   bool operator()(const typename _Predicate::argument_type& __x) const {
00152     return !_M_pred(__x);
00153   }
00154 };
00155 
00156 template <class _Predicate>
00157 inline unary_negate<_Predicate> 
00158 not1(const _Predicate& __pred)
00159 {
00160   return unary_negate<_Predicate>(__pred);
00161 }
00162 
00163 template <class _Predicate> 
00164 class binary_negate 
00165   : public binary_function<typename _Predicate::first_argument_type,
00166                            typename _Predicate::second_argument_type,
00167                            bool> {
00168 protected:
00169   _Predicate _M_pred;
00170 public:
00171   explicit binary_negate(const _Predicate& __x) : _M_pred(__x) {}
00172   bool operator()(const typename _Predicate::first_argument_type& __x, 
00173                   const typename _Predicate::second_argument_type& __y) const
00174   {
00175     return !_M_pred(__x, __y); 
00176   }
00177 };
00178 
00179 template <class _Predicate>
00180 inline binary_negate<_Predicate> 
00181 not2(const _Predicate& __pred)
00182 {
00183   return binary_negate<_Predicate>(__pred);
00184 }
00185 
00186 template <class _Operation> 
00187 class binder1st
00188   : public unary_function<typename _Operation::second_argument_type,
00189                           typename _Operation::result_type> {
00190 protected:
00191   _Operation op;
00192   typename _Operation::first_argument_type value;
00193 public:
00194   binder1st(const _Operation& __x,
00195             const typename _Operation::first_argument_type& __y)
00196       : op(__x), value(__y) {}
00197   typename _Operation::result_type
00198   operator()(const typename _Operation::second_argument_type& __x) const {
00199     return op(value, __x); 
00200   }
00201 };
00202 
00203 template <class _Operation, class _Tp>
00204 inline binder1st<_Operation> 
00205 bind1st(const _Operation& __fn, const _Tp& __x) 
00206 {
00207   typedef typename _Operation::first_argument_type _Arg1_type;
00208   return binder1st<_Operation>(__fn, _Arg1_type(__x));
00209 }
00210 
00211 template <class _Operation> 
00212 class binder2nd
00213   : public unary_function<typename _Operation::first_argument_type,
00214                           typename _Operation::result_type> {
00215 protected:
00216   _Operation op;
00217   typename _Operation::second_argument_type value;
00218 public:
00219   binder2nd(const _Operation& __x,
00220             const typename _Operation::second_argument_type& __y) 
00221       : op(__x), value(__y) {}
00222   typename _Operation::result_type
00223   operator()(const typename _Operation::first_argument_type& __x) const {
00224     return op(__x, value); 
00225   }
00226 };
00227 
00228 template <class _Operation, class _Tp>
00229 inline binder2nd<_Operation> 
00230 bind2nd(const _Operation& __fn, const _Tp& __x) 
00231 {
00232   typedef typename _Operation::second_argument_type _Arg2_type;
00233   return binder2nd<_Operation>(__fn, _Arg2_type(__x));
00234 }
00235 
00236 // unary_compose and binary_compose (extensions, not part of the standard).
00237 
00238 template <class _Operation1, class _Operation2>
00239 class unary_compose
00240   : public unary_function<typename _Operation2::argument_type,
00241                           typename _Operation1::result_type> 
00242 {
00243 protected:
00244   _Operation1 _M_fn1;
00245   _Operation2 _M_fn2;
00246 public:
00247   unary_compose(const _Operation1& __x, const _Operation2& __y) 
00248     : _M_fn1(__x), _M_fn2(__y) {}
00249   typename _Operation1::result_type
00250   operator()(const typename _Operation2::argument_type& __x) const {
00251     return _M_fn1(_M_fn2(__x));
00252   }
00253 };
00254 
00255 template <class _Operation1, class _Operation2>
00256 inline unary_compose<_Operation1,_Operation2> 
00257 compose1(const _Operation1& __fn1, const _Operation2& __fn2)
00258 {
00259   return unary_compose<_Operation1,_Operation2>(__fn1, __fn2);
00260 }
00261 
00262 template <class _Operation1, class _Operation2, class _Operation3>
00263 class binary_compose
00264   : public unary_function<typename _Operation2::argument_type,
00265                           typename _Operation1::result_type> {
00266 protected:
00267   _Operation1 _M_fn1;
00268   _Operation2 _M_fn2;
00269   _Operation3 _M_fn3;
00270 public:
00271   binary_compose(const _Operation1& __x, const _Operation2& __y, 
00272                  const _Operation3& __z) 
00273     : _M_fn1(__x), _M_fn2(__y), _M_fn3(__z) { }
00274   typename _Operation1::result_type
00275   operator()(const typename _Operation2::argument_type& __x) const {
00276     return _M_fn1(_M_fn2(__x), _M_fn3(__x));
00277   }
00278 };
00279 
00280 template <class _Operation1, class _Operation2, class _Operation3>
00281 inline binary_compose<_Operation1, _Operation2, _Operation3> 
00282 compose2(const _Operation1& __fn1, const _Operation2& __fn2, 
00283          const _Operation3& __fn3)
00284 {
00285   return binary_compose<_Operation1,_Operation2,_Operation3>
00286     (__fn1, __fn2, __fn3);
00287 }
00288 
00289 template <class _Arg, class _Result>
00290 class pointer_to_unary_function : public unary_function<_Arg, _Result> {
00291 protected:
00292   _Result (*_M_ptr)(_Arg);
00293 public:
00294   pointer_to_unary_function() {}
00295   explicit pointer_to_unary_function(_Result (*__x)(_Arg)) : _M_ptr(__x) {}
00296   _Result operator()(_Arg __x) const { return _M_ptr(__x); }
00297 };
00298 
00299 template <class _Arg, class _Result>
00300 inline pointer_to_unary_function<_Arg, _Result> ptr_fun(_Result (*__x)(_Arg))
00301 {
00302   return pointer_to_unary_function<_Arg, _Result>(__x);
00303 }
00304 
00305 template <class _Arg1, class _Arg2, class _Result>
00306 class pointer_to_binary_function : 
00307   public binary_function<_Arg1,_Arg2,_Result> {
00308 protected:
00309     _Result (*_M_ptr)(_Arg1, _Arg2);
00310 public:
00311     pointer_to_binary_function() {}
00312     explicit pointer_to_binary_function(_Result (*__x)(_Arg1, _Arg2)) 
00313       : _M_ptr(__x) {}
00314     _Result operator()(_Arg1 __x, _Arg2 __y) const {
00315       return _M_ptr(__x, __y);
00316     }
00317 };
00318 
00319 template <class _Arg1, class _Arg2, class _Result>
00320 inline pointer_to_binary_function<_Arg1,_Arg2,_Result> 
00321 ptr_fun(_Result (*__x)(_Arg1, _Arg2)) {
00322   return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__x);
00323 }
00324 
00325 // identity is an extensions: it is not part of the standard.
00326 template <class _Tp>
00327 struct _Identity : public unary_function<_Tp,_Tp> {
00328   const _Tp& operator()(const _Tp& __x) const { return __x; }
00329 };
00330 
00331 template <class _Tp> struct identity : public _Identity<_Tp> {};
00332 
00333 // select1st and select2nd are extensions: they are not part of the standard.
00334 template <class _Pair>
00335 struct _Select1st : public unary_function<_Pair, typename _Pair::first_type> {
00336   const typename _Pair::first_type& operator()(const _Pair& __x) const {
00337     return __x.first;
00338   }
00339 };
00340 
00341 template <class _Pair>
00342 struct _Select2nd : public unary_function<_Pair, typename _Pair::second_type>
00343 {
00344   const typename _Pair::second_type& operator()(const _Pair& __x) const {
00345     return __x.second;
00346   }
00347 };
00348 
00349 template <class _Pair> struct select1st : public _Select1st<_Pair> {};
00350 template <class _Pair> struct select2nd : public _Select2nd<_Pair> {};
00351 
00352 // project1st and project2nd are extensions: they are not part of the standard
00353 template <class _Arg1, class _Arg2>
00354 struct _Project1st : public binary_function<_Arg1, _Arg2, _Arg1> {
00355   _Arg1 operator()(const _Arg1& __x, const _Arg2&) const { return __x; }
00356 };
00357 
00358 template <class _Arg1, class _Arg2>
00359 struct _Project2nd : public binary_function<_Arg1, _Arg2, _Arg2> {
00360   _Arg2 operator()(const _Arg1&, const _Arg2& __y) const { return __y; }
00361 };
00362 
00363 template <class _Arg1, class _Arg2> 
00364 struct project1st : public _Project1st<_Arg1, _Arg2> {};
00365 
00366 template <class _Arg1, class _Arg2>
00367 struct project2nd : public _Project2nd<_Arg1, _Arg2> {};
00368 
00369 // constant_void_fun, constant_unary_fun, and constant_binary_fun are
00370 // extensions: they are not part of the standard.  (The same, of course,
00371 // is true of the helper functions constant0, constant1, and constant2.)
00372 
00373 template <class _Result>
00374 struct _Constant_void_fun {
00375   typedef _Result result_type;
00376   result_type _M_val;
00377 
00378   _Constant_void_fun(const result_type& __v) : _M_val(__v) {}
00379   const result_type& operator()() const { return _M_val; }
00380 };  
00381 
00382 template <class _Result, class _Argument>
00383 struct _Constant_unary_fun {
00384   typedef _Argument argument_type;
00385   typedef  _Result  result_type;
00386   result_type _M_val;
00387 
00388   _Constant_unary_fun(const result_type& __v) : _M_val(__v) {}
00389   const result_type& operator()(const _Argument&) const { return _M_val; }
00390 };
00391 
00392 template <class _Result, class _Arg1, class _Arg2>
00393 struct _Constant_binary_fun {
00394   typedef  _Arg1   first_argument_type;
00395   typedef  _Arg2   second_argument_type;
00396   typedef  _Result result_type;
00397   _Result _M_val;
00398 
00399   _Constant_binary_fun(const _Result& __v) : _M_val(__v) {}
00400   const result_type& operator()(const _Arg1&, const _Arg2&) const {
00401     return _M_val;
00402   }
00403 };
00404 
00405 template <class _Result>
00406 struct constant_void_fun : public _Constant_void_fun<_Result> {
00407   constant_void_fun(const _Result& __v) : _Constant_void_fun<_Result>(__v) {}
00408 };  
00409 
00410 
00411 template <class _Result,
00412           class _Argument __STL_DEPENDENT_DEFAULT_TMPL(_Result)>
00413 struct constant_unary_fun : public _Constant_unary_fun<_Result, _Argument>
00414 {
00415   constant_unary_fun(const _Result& __v)
00416     : _Constant_unary_fun<_Result, _Argument>(__v) {}
00417 };
00418 
00419 
00420 template <class _Result,
00421           class _Arg1 __STL_DEPENDENT_DEFAULT_TMPL(_Result),
00422           class _Arg2 __STL_DEPENDENT_DEFAULT_TMPL(_Arg1)>
00423 struct constant_binary_fun
00424   : public _Constant_binary_fun<_Result, _Arg1, _Arg2>
00425 {
00426   constant_binary_fun(const _Result& __v)
00427     : _Constant_binary_fun<_Result, _Arg1, _Arg2>(__v) {}
00428 };
00429 
00430 template <class _Result>
00431 inline constant_void_fun<_Result> constant0(const _Result& __val)
00432 {
00433   return constant_void_fun<_Result>(__val);
00434 }
00435 
00436 template <class _Result>
00437 inline constant_unary_fun<_Result,_Result> constant1(const _Result& __val)
00438 {
00439   return constant_unary_fun<_Result,_Result>(__val);
00440 }
00441 
00442 template <class _Result>
00443 inline constant_binary_fun<_Result,_Result,_Result> 
00444 constant2(const _Result& __val)
00445 {
00446   return constant_binary_fun<_Result,_Result,_Result>(__val);
00447 }
00448 
00449 // subtractive_rng is an extension: it is not part of the standard.
00450 // Note: this code assumes that int is 32 bits.
00451 class subtractive_rng : public unary_function<unsigned int, unsigned int> {
00452 private:
00453   unsigned int _M_table[55];
00454   size_t _M_index1;
00455   size_t _M_index2;
00456 public:
00457   unsigned int operator()(unsigned int __limit) {
00458     _M_index1 = (_M_index1 + 1) % 55;
00459     _M_index2 = (_M_index2 + 1) % 55;
00460     _M_table[_M_index1] = _M_table[_M_index1] - _M_table[_M_index2];
00461     return _M_table[_M_index1] % __limit;
00462   }
00463 
00464   void _M_initialize(unsigned int __seed)
00465   {
00466     unsigned int __k = 1;
00467     _M_table[54] = __seed;
00468     size_t __i;
00469     for (__i = 0; __i < 54; __i++) {
00470         size_t __ii = (21 * (__i + 1) % 55) - 1;
00471         _M_table[__ii] = __k;
00472         __k = __seed - __k;
00473         __seed = _M_table[__ii];
00474     }
00475     for (int __loop = 0; __loop < 4; __loop++) {
00476         for (__i = 0; __i < 55; __i++)
00477             _M_table[__i] = _M_table[__i] - _M_table[(1 + __i + 30) % 55];
00478     }
00479     _M_index1 = 0;
00480     _M_index2 = 31;
00481   }
00482 
00483   subtractive_rng(unsigned int __seed) { _M_initialize(__seed); }
00484   subtractive_rng() { _M_initialize(161803398u); }
00485 };
00486 
00487 
00488 // Adaptor function objects: pointers to member functions.
00489 
00490 // There are a total of 16 = 2^4 function objects in this family.
00491 //  (1) Member functions taking no arguments vs member functions taking
00492 //       one argument.
00493 //  (2) Call through pointer vs call through reference.
00494 //  (3) Member function with void return type vs member function with
00495 //      non-void return type.
00496 //  (4) Const vs non-const member function.
00497 
00498 // Note that choice (3) is nothing more than a workaround: according
00499 //  to the draft, compilers should handle void and non-void the same way.
00500 //  This feature is not yet widely implemented, though.  You can only use
00501 //  member functions returning void if your compiler supports partial
00502 //  specialization.
00503 
00504 // All of this complexity is in the function objects themselves.  You can
00505 //  ignore it by using the helper function mem_fun and mem_fun_ref,
00506 //  which create whichever type of adaptor is appropriate.
00507 //  (mem_fun1 and mem_fun1_ref are no longer part of the C++ standard,
00508 //  but they are provided for backward compatibility.)
00509 
00510 
00511 template <class _Ret, class _Tp>
00512 class mem_fun_t : public unary_function<_Tp*,_Ret> {
00513 public:
00514   explicit mem_fun_t(_Ret (_Tp::*__pf)()) : _M_f(__pf) {}
00515   _Ret operator()(_Tp* __p) const { return (__p->*_M_f)(); }
00516 private:
00517   _Ret (_Tp::*_M_f)();
00518 };
00519 
00520 template <class _Ret, class _Tp>
00521 class const_mem_fun_t : public unary_function<const _Tp*,_Ret> {
00522 public:
00523   explicit const_mem_fun_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}
00524   _Ret operator()(const _Tp* __p) const { return (__p->*_M_f)(); }
00525 private:
00526   _Ret (_Tp::*_M_f)() const;
00527 };
00528 
00529 
00530 template <class _Ret, class _Tp>
00531 class mem_fun_ref_t : public unary_function<_Tp,_Ret> {
00532 public:
00533   explicit mem_fun_ref_t(_Ret (_Tp::*__pf)()) : _M_f(__pf) {}
00534   _Ret operator()(_Tp& __r) const { return (__r.*_M_f)(); }
00535 private:
00536   _Ret (_Tp::*_M_f)();
00537 };
00538 
00539 template <class _Ret, class _Tp>
00540 class const_mem_fun_ref_t : public unary_function<_Tp,_Ret> {
00541 public:
00542   explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}
00543   _Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); }
00544 private:
00545   _Ret (_Tp::*_M_f)() const;
00546 };
00547 
00548 template <class _Ret, class _Tp, class _Arg>
00549 class mem_fun1_t : public binary_function<_Tp*,_Arg,_Ret> {
00550 public:
00551   explicit mem_fun1_t(_Ret (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}
00552   _Ret operator()(_Tp* __p, _Arg __x) const { return (__p->*_M_f)(__x); }
00553 private:
00554   _Ret (_Tp::*_M_f)(_Arg);
00555 };
00556 
00557 template <class _Ret, class _Tp, class _Arg>
00558 class const_mem_fun1_t : public binary_function<const _Tp*,_Arg,_Ret> {
00559 public:
00560   explicit const_mem_fun1_t(_Ret (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {}
00561   _Ret operator()(const _Tp* __p, _Arg __x) const
00562     { return (__p->*_M_f)(__x); }
00563 private:
00564   _Ret (_Tp::*_M_f)(_Arg) const;
00565 };
00566 
00567 template <class _Ret, class _Tp, class _Arg>
00568 class mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> {
00569 public:
00570   explicit mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}
00571   _Ret operator()(_Tp& __r, _Arg __x) const { return (__r.*_M_f)(__x); }
00572 private:
00573   _Ret (_Tp::*_M_f)(_Arg);
00574 };
00575 
00576 template <class _Ret, class _Tp, class _Arg>
00577 class const_mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> {
00578 public:
00579   explicit const_mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {}
00580   _Ret operator()(const _Tp& __r, _Arg __x) const { return (__r.*_M_f)(__x); }
00581 private:
00582   _Ret (_Tp::*_M_f)(_Arg) const;
00583 };
00584 
00585 #ifdef __STL_CLASS_PARTIAL_SPECIALIZATION
00586 
00587 template <class _Tp>
00588 class mem_fun_t<void, _Tp> : public unary_function<_Tp*,void> {
00589 public:
00590   explicit mem_fun_t(void (_Tp::*__pf)()) : _M_f(__pf) {}
00591   void operator()(_Tp* __p) const { (__p->*_M_f)(); }
00592 private:
00593   void (_Tp::*_M_f)();
00594 };
00595 
00596 template <class _Tp>
00597 class const_mem_fun_t<void, _Tp> : public unary_function<const _Tp*,void> {
00598 public:
00599   explicit const_mem_fun_t(void (_Tp::*__pf)() const) : _M_f(__pf) {}
00600   void operator()(const _Tp* __p) const { (__p->*_M_f)(); }
00601 private:
00602   void (_Tp::*_M_f)() const;
00603 };
00604 
00605 template <class _Tp>
00606 class mem_fun_ref_t<void, _Tp> : public unary_function<_Tp,void> {
00607 public:
00608   explicit mem_fun_ref_t(void (_Tp::*__pf)()) : _M_f(__pf) {}
00609   void operator()(_Tp& __r) const { (__r.*_M_f)(); }
00610 private:
00611   void (_Tp::*_M_f)();
00612 };
00613 
00614 template <class _Tp>
00615 class const_mem_fun_ref_t<void, _Tp> : public unary_function<_Tp,void> {
00616 public:
00617   explicit const_mem_fun_ref_t(void (_Tp::*__pf)() const) : _M_f(__pf) {}
00618   void operator()(const _Tp& __r) const { (__r.*_M_f)(); }
00619 private:
00620   void (_Tp::*_M_f)() const;
00621 };
00622 
00623 template <class _Tp, class _Arg>
00624 class mem_fun1_t<void, _Tp, _Arg> : public binary_function<_Tp*,_Arg,void> {
00625 public:
00626   explicit mem_fun1_t(void (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}
00627   void operator()(_Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }
00628 private:
00629   void (_Tp::*_M_f)(_Arg);
00630 };
00631 
00632 template <class _Tp, class _Arg>
00633 class const_mem_fun1_t<void, _Tp, _Arg> 
00634   : public binary_function<const _Tp*,_Arg,void> {
00635 public:
00636   explicit const_mem_fun1_t(void (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {}
00637   void operator()(const _Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }
00638 private:
00639   void (_Tp::*_M_f)(_Arg) const;
00640 };
00641 
00642 template <class _Tp, class _Arg>
00643 class mem_fun1_ref_t<void, _Tp, _Arg>
00644   : public binary_function<_Tp,_Arg,void> {
00645 public:
00646   explicit mem_fun1_ref_t(void (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}
00647   void operator()(_Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); }
00648 private:
00649   void (_Tp::*_M_f)(_Arg);
00650 };
00651 
00652 template <class _Tp, class _Arg>
00653 class const_mem_fun1_ref_t<void, _Tp, _Arg>
00654   : public binary_function<_Tp,_Arg,void> {
00655 public:
00656   explicit const_mem_fun1_ref_t(void (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {}
00657   void operator()(const _Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); }
00658 private:
00659   void (_Tp::*_M_f)(_Arg) const;
00660 };
00661 
00662 #endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
00663 
00664 // Mem_fun adaptor helper functions.  There are only two:
00665 //  mem_fun and mem_fun_ref.  (mem_fun1 and mem_fun1_ref 
00666 //  are provided for backward compatibility, but they are no longer
00667 //  part of the C++ standard.)
00668 
00669 template <class _Ret, class _Tp>
00670 inline mem_fun_t<_Ret,_Tp> mem_fun(_Ret (_Tp::*__f)())
00671   { return mem_fun_t<_Ret,_Tp>(__f); }
00672 
00673 template <class _Ret, class _Tp>
00674 inline const_mem_fun_t<_Ret,_Tp> mem_fun(_Ret (_Tp::*__f)() const)
00675   { return const_mem_fun_t<_Ret,_Tp>(__f); }
00676 
00677 template <class _Ret, class _Tp>
00678 inline mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)()) 
00679   { return mem_fun_ref_t<_Ret,_Tp>(__f); }
00680 
00681 template <class _Ret, class _Tp>
00682 inline const_mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)() const)
00683   { return const_mem_fun_ref_t<_Ret,_Tp>(__f); }
00684 
00685 template <class _Ret, class _Tp, class _Arg>
00686 inline mem_fun1_t<_Ret,_Tp,_Arg> mem_fun(_Ret (_Tp::*__f)(_Arg))
00687   { return mem_fun1_t<_Ret,_Tp,_Arg>(__f); }
00688 
00689 template <class _Ret, class _Tp, class _Arg>
00690 inline const_mem_fun1_t<_Ret,_Tp,_Arg> mem_fun(_Ret (_Tp::*__f)(_Arg) const)
00691   { return const_mem_fun1_t<_Ret,_Tp,_Arg>(__f); }
00692 
00693 template <class _Ret, class _Tp, class _Arg>
00694 inline mem_fun1_ref_t<_Ret,_Tp,_Arg> mem_fun_ref(_Ret (_Tp::*__f)(_Arg))
00695   { return mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }
00696 
00697 template <class _Ret, class _Tp, class _Arg>
00698 inline const_mem_fun1_ref_t<_Ret,_Tp,_Arg>
00699 mem_fun_ref(_Ret (_Tp::*__f)(_Arg) const)
00700   { return const_mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }
00701 
00702 template <class _Ret, class _Tp, class _Arg>
00703 inline mem_fun1_t<_Ret,_Tp,_Arg> mem_fun1(_Ret (_Tp::*__f)(_Arg))
00704   { return mem_fun1_t<_Ret,_Tp,_Arg>(__f); }
00705 
00706 template <class _Ret, class _Tp, class _Arg>
00707 inline const_mem_fun1_t<_Ret,_Tp,_Arg> mem_fun1(_Ret (_Tp::*__f)(_Arg) const)
00708   { return const_mem_fun1_t<_Ret,_Tp,_Arg>(__f); }
00709 
00710 template <class _Ret, class _Tp, class _Arg>
00711 inline mem_fun1_ref_t<_Ret,_Tp,_Arg> mem_fun1_ref(_Ret (_Tp::*__f)(_Arg))
00712   { return mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }
00713 
00714 template <class _Ret, class _Tp, class _Arg>
00715 inline const_mem_fun1_ref_t<_Ret,_Tp,_Arg>
00716 mem_fun1_ref(_Ret (_Tp::*__f)(_Arg) const)
00717   { return const_mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }
00718 
00719 __STL_END_NAMESPACE
00720 
00721 #endif /* __SGI_STL_INTERNAL_FUNCTION_H */
00722 
00723 // Local Variables:
00724 // mode:C++
00725 // End:

Generated on Mon Jun 5 10:20:44 2006 for Intelligence.kdevelop by  doxygen 1.4.6