00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00061 #ifndef _FUNCTION_H
00062 #define _FUNCTION_H 1
00063
00064 namespace std
00065 {
00066
00101 template <class _Arg, class _Result>
00102 struct unary_function
00103 {
00104 typedef _Arg argument_type;
00105
00106
00107 typedef _Result result_type;
00108 };
00109
00113 template <class _Arg1, class _Arg2, class _Result>
00114 struct binary_function
00115 {
00116 typedef _Arg1 first_argument_type;
00117
00118
00119 typedef _Arg2 second_argument_type;
00120 typedef _Result result_type;
00121 };
00124
00132
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
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
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
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
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
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 };
00187
00194
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
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
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
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
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
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 };
00249
00255
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
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
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 };
00283
00310
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
00327 template <class _Predicate>
00328 inline unary_negate<_Predicate>
00329 not1(const _Predicate& __pred)
00330 { return unary_negate<_Predicate>(__pred); }
00331
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
00353 template <class _Predicate>
00354 inline binary_negate<_Predicate>
00355 not2(const _Predicate& __pred)
00356 { return binary_negate<_Predicate>(__pred); }
00359
00390
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
00409
00410 typename _Operation::result_type
00411 operator()(typename _Operation::second_argument_type& __x) const
00412 { return op(value, __x); }
00413 };
00414
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
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
00443
00444 typename _Operation::result_type
00445 operator()(typename _Operation::first_argument_type& __x) const
00446 { return op(__x, value); }
00447 };
00448
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 }
00459
00479
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
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
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
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); }
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
00581
00582 template <class _Ret, class _Tp>
00583 class mem_fun_t : public unary_function<_Tp*, _Ret>
00584 {
00585 public:
00586 explicit
00587 mem_fun_t(_Ret (_Tp::*__pf)())
00588 : _M_f(__pf) {}
00589
00590 _Ret
00591 operator()(_Tp* __p) const
00592 { return (__p->*_M_f)(); }
00593 private:
00594 _Ret (_Tp::*_M_f)();
00595 };
00596
00598 template <class _Ret, class _Tp>
00599 class const_mem_fun_t : public unary_function<const _Tp*, _Ret>
00600 {
00601 public:
00602 explicit
00603 const_mem_fun_t(_Ret (_Tp::*__pf)() const)
00604 : _M_f(__pf) {}
00605
00606 _Ret
00607 operator()(const _Tp* __p) const
00608 { return (__p->*_M_f)(); }
00609 private:
00610 _Ret (_Tp::*_M_f)() const;
00611 };
00612
00614 template <class _Ret, class _Tp>
00615 class mem_fun_ref_t : public unary_function<_Tp, _Ret>
00616 {
00617 public:
00618 explicit
00619 mem_fun_ref_t(_Ret (_Tp::*__pf)())
00620 : _M_f(__pf) {}
00621
00622 _Ret
00623 operator()(_Tp& __r) const
00624 { return (__r.*_M_f)(); }
00625 private:
00626 _Ret (_Tp::*_M_f)();
00627 };
00628
00630 template <class _Ret, class _Tp>
00631 class const_mem_fun_ref_t : public unary_function<_Tp, _Ret>
00632 {
00633 public:
00634 explicit
00635 const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const)
00636 : _M_f(__pf) {}
00637
00638 _Ret
00639 operator()(const _Tp& __r) const
00640 { return (__r.*_M_f)(); }
00641 private:
00642 _Ret (_Tp::*_M_f)() const;
00643 };
00644
00646 template <class _Ret, class _Tp, class _Arg>
00647 class mem_fun1_t : public binary_function<_Tp*, _Arg, _Ret>
00648 {
00649 public:
00650 explicit
00651 mem_fun1_t(_Ret (_Tp::*__pf)(_Arg))
00652 : _M_f(__pf) {}
00653
00654 _Ret
00655 operator()(_Tp* __p, _Arg __x) const
00656 { return (__p->*_M_f)(__x); }
00657 private:
00658 _Ret (_Tp::*_M_f)(_Arg);
00659 };
00660
00662 template <class _Ret, class _Tp, class _Arg>
00663 class const_mem_fun1_t : public binary_function<const _Tp*, _Arg, _Ret>
00664 {
00665 public:
00666 explicit
00667 const_mem_fun1_t(_Ret (_Tp::*__pf)(_Arg) const)
00668 : _M_f(__pf) {}
00669
00670 _Ret
00671 operator()(const _Tp* __p, _Arg __x) const
00672 { return (__p->*_M_f)(__x); }
00673 private:
00674 _Ret (_Tp::*_M_f)(_Arg) const;
00675 };
00676
00678 template <class _Ret, class _Tp, class _Arg>
00679 class mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret>
00680 {
00681 public:
00682 explicit
00683 mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg))
00684 : _M_f(__pf) {}
00685
00686 _Ret
00687 operator()(_Tp& __r, _Arg __x) const
00688 { return (__r.*_M_f)(__x); }
00689 private:
00690 _Ret (_Tp::*_M_f)(_Arg);
00691 };
00692
00694 template <class _Ret, class _Tp, class _Arg>
00695 class const_mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret>
00696 {
00697 public:
00698 explicit
00699 const_mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg) const)
00700 : _M_f(__pf) {}
00701
00702 _Ret
00703 operator()(const _Tp& __r, _Arg __x) const
00704 { return (__r.*_M_f)(__x); }
00705 private:
00706 _Ret (_Tp::*_M_f)(_Arg) const;
00707 };
00708
00709
00710
00711 template <class _Ret, class _Tp>
00712 inline mem_fun_t<_Ret, _Tp>
00713 mem_fun(_Ret (_Tp::*__f)())
00714 { return mem_fun_t<_Ret, _Tp>(__f); }
00715
00716 template <class _Ret, class _Tp>
00717 inline const_mem_fun_t<_Ret, _Tp>
00718 mem_fun(_Ret (_Tp::*__f)() const)
00719 { return const_mem_fun_t<_Ret, _Tp>(__f); }
00720
00721 template <class _Ret, class _Tp>
00722 inline mem_fun_ref_t<_Ret, _Tp>
00723 mem_fun_ref(_Ret (_Tp::*__f)())
00724 { return mem_fun_ref_t<_Ret, _Tp>(__f); }
00725
00726 template <class _Ret, class _Tp>
00727 inline const_mem_fun_ref_t<_Ret, _Tp>
00728 mem_fun_ref(_Ret (_Tp::*__f)() const)
00729 { return const_mem_fun_ref_t<_Ret, _Tp>(__f); }
00730
00731 template <class _Ret, class _Tp, class _Arg>
00732 inline mem_fun1_t<_Ret, _Tp, _Arg>
00733 mem_fun(_Ret (_Tp::*__f)(_Arg))
00734 { return mem_fun1_t<_Ret, _Tp, _Arg>(__f); }
00735
00736 template <class _Ret, class _Tp, class _Arg>
00737 inline const_mem_fun1_t<_Ret, _Tp, _Arg>
00738 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>
00743 mem_fun_ref(_Ret (_Tp::*__f)(_Arg))
00744 { return mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); }
00745
00746 template <class _Ret, class _Tp, class _Arg>
00747 inline const_mem_fun1_ref_t<_Ret, _Tp, _Arg>
00748 mem_fun_ref(_Ret (_Tp::*__f)(_Arg) const)
00749 { return const_mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); }
00750
00753 }
00754
00755 #endif
00756
00757
00758
00759