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