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
00056
00057
00058
00059
00060
00061 #ifndef _FUNCTION_H
00062 #define _FUNCTION_H 1
00063
00064 namespace std
00065 {
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
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
00110
00111
00112
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 };
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
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
00141
00142 template <class _Tp>
00143 struct minus : public binary_function<_Tp, _Tp, _Tp>
00144 {
00145 _Tp
00146 operator()(const _Tp& __x, const _Tp& __y) const
00147 { return __x - __y; }
00148 };
00149
00150
00151 template <class _Tp>
00152 struct multiplies : public binary_function<_Tp, _Tp, _Tp>
00153 {
00154 _Tp
00155 operator()(const _Tp& __x, const _Tp& __y) const
00156 { return __x * __y; }
00157 };
00158
00159
00160 template <class _Tp>
00161 struct divides : public binary_function<_Tp, _Tp, _Tp>
00162 {
00163 _Tp
00164 operator()(const _Tp& __x, const _Tp& __y) const
00165 { return __x / __y; }
00166 };
00167
00168
00169 template <class _Tp>
00170 struct modulus : public binary_function<_Tp, _Tp, _Tp>
00171 {
00172 _Tp
00173 operator()(const _Tp& __x, const _Tp& __y) const
00174 { return __x % __y; }
00175 };
00176
00177
00178 template <class _Tp>
00179 struct negate : public unary_function<_Tp, _Tp>
00180 {
00181 _Tp
00182 operator()(const _Tp& __x) const
00183 { return -__x; }
00184 };
00185
00186
00187
00188
00189
00190
00191
00192
00193
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
00203
00204 template <class _Tp>
00205 struct not_equal_to : public binary_function<_Tp, _Tp, bool>
00206 {
00207 bool
00208 operator()(const _Tp& __x, const _Tp& __y) const
00209 { return __x != __y; }
00210 };
00211
00212
00213 template <class _Tp>
00214 struct greater : public binary_function<_Tp, _Tp, bool>
00215 {
00216 bool
00217 operator()(const _Tp& __x, const _Tp& __y) const
00218 { return __x > __y; }
00219 };
00220
00221
00222 template <class _Tp>
00223 struct less : public binary_function<_Tp, _Tp, bool>
00224 {
00225 bool
00226 operator()(const _Tp& __x, const _Tp& __y) const
00227 { return __x < __y; }
00228 };
00229
00230
00231 template <class _Tp>
00232 struct greater_equal : public binary_function<_Tp, _Tp, bool>
00233 {
00234 bool
00235 operator()(const _Tp& __x, const _Tp& __y) const
00236 { return __x >= __y; }
00237 };
00238
00239
00240 template <class _Tp>
00241 struct less_equal : public binary_function<_Tp, _Tp, bool>
00242 {
00243 bool
00244 operator()(const _Tp& __x, const _Tp& __y) const
00245 { return __x <= __y; }
00246 };
00247
00248
00249
00250
00251
00252
00253
00254
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
00264
00265 template <class _Tp>
00266 struct logical_or : public binary_function<_Tp, _Tp, bool>
00267 {
00268 bool
00269 operator()(const _Tp& __x, const _Tp& __y) const
00270 { return __x || __y; }
00271 };
00272
00273
00274 template <class _Tp>
00275 struct logical_not : public unary_function<_Tp, bool>
00276 {
00277 bool
00278 operator()(const _Tp& __x) const
00279 { return !__x; }
00280 };
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
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
00326
00327 template <class _Predicate>
00328 inline unary_negate<_Predicate>
00329 not1(const _Predicate& __pred)
00330 { return unary_negate<_Predicate>(__pred); }
00331
00332
00333 template <class _Predicate>
00334 class binary_negate
00335 : public binary_function<typename _Predicate::first_argument_type,
00336 typename _Predicate::second_argument_type,
00337 bool>
00338 {
00339 protected:
00340 _Predicate _M_pred;
00341 public:
00342 explicit
00343 binary_negate(const _Predicate& __x)
00344 : _M_pred(__x) { }
00345
00346 bool
00347 operator()(const typename _Predicate::first_argument_type& __x,
00348 const typename _Predicate::second_argument_type& __y) const
00349 { return !_M_pred(__x, __y); }
00350 };
00351
00352
00353 template <class _Predicate>
00354 inline binary_negate<_Predicate>
00355 not2(const _Predicate& __pred)
00356 { return binary_negate<_Predicate>(__pred); }
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
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
00415
00416 template <class _Operation, class _Tp>
00417 inline binder1st<_Operation>
00418 bind1st(const _Operation& __fn, const _Tp& __x)
00419 {
00420 typedef typename _Operation::first_argument_type _Arg1_type;
00421 return binder1st<_Operation>(__fn, _Arg1_type(__x));
00422 }
00423
00424
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
00449
00450 template <class _Operation, class _Tp>
00451 inline binder2nd<_Operation>
00452 bind2nd(const _Operation& __fn, const _Tp& __x)
00453 {
00454 typedef typename _Operation::second_argument_type _Arg2_type;
00455 return binder2nd<_Operation>(__fn, _Arg2_type(__x));
00456 }
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
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
00497
00498 template <class _Arg, class _Result>
00499 inline pointer_to_unary_function<_Arg, _Result>
00500 ptr_fun(_Result (*__x)(_Arg))
00501 { return pointer_to_unary_function<_Arg, _Result>(__x); }
00502
00503
00504 template <class _Arg1, class _Arg2, class _Result>
00505 class pointer_to_binary_function
00506 : public binary_function<_Arg1, _Arg2, _Result>
00507 {
00508 protected:
00509 _Result (*_M_ptr)(_Arg1, _Arg2);
00510 public:
00511 pointer_to_binary_function() {}
00512
00513 explicit
00514 pointer_to_binary_function(_Result (*__x)(_Arg1, _Arg2))
00515 : _M_ptr(__x) {}
00516
00517 _Result
00518 operator()(_Arg1 __x, _Arg2 __y) const
00519 { return _M_ptr(__x, __y); }
00520 };
00521
00522
00523 template <class _Arg1, class _Arg2, class _Result>
00524 inline pointer_to_binary_function<_Arg1, _Arg2, _Result>
00525 ptr_fun(_Result (*__x)(_Arg1, _Arg2))
00526 { return pointer_to_binary_function<_Arg1, _Arg2, _Result>(__x); }
00527
00528
00529 template <class _Tp>
00530 struct _Identity : public unary_function<_Tp,_Tp>
00531 {
00532 _Tp&
00533 operator()(_Tp& __x) const
00534 { return __x; }
00535
00536 const _Tp&
00537 operator()(const _Tp& __x) const
00538 { return __x; }
00539 };
00540
00541 template <class _Pair>
00542 struct _Select1st : public unary_function<_Pair,
00543 typename _Pair::first_type>
00544 {
00545 typename _Pair::first_type&
00546 operator()(_Pair& __x) const
00547 { return __x.first; }
00548
00549 const typename _Pair::first_type&
00550 operator()(const _Pair& __x) const
00551 { return __x.first; }
00552 };
00553
00554 template <class _Pair>
00555 struct _Select2nd : public unary_function<_Pair,
00556 typename _Pair::second_type>
00557 {
00558 typename _Pair::second_type&
00559 operator()(_Pair& __x) const
00560 { return __x.second; }
00561
00562 const typename _Pair::second_type&
00563 operator()(const _Pair& __x) const
00564 { return __x.second; }
00565 };
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590 template <class _Ret, class _Tp>
00591 class mem_fun_t : public unary_function<_Tp*, _Ret>
00592 {
00593 public:
00594 explicit
00595 mem_fun_t(_Ret (_Tp::*__pf)())
00596 : _M_f(__pf) {}
00597
00598 _Ret
00599 operator()(_Tp* __p) const
00600 { return (__p->*_M_f)(); }
00601 private:
00602 _Ret (_Tp::*_M_f)();
00603 };
00604
00605
00606 template <class _Ret, class _Tp>
00607 class const_mem_fun_t : public unary_function<const _Tp*, _Ret>
00608 {
00609 public:
00610 explicit
00611 const_mem_fun_t(_Ret (_Tp::*__pf)() const)
00612 : _M_f(__pf) {}
00613
00614 _Ret
00615 operator()(const _Tp* __p) const
00616 { return (__p->*_M_f)(); }
00617 private:
00618 _Ret (_Tp::*_M_f)() const;
00619 };
00620
00621
00622 template <class _Ret, class _Tp>
00623 class mem_fun_ref_t : public unary_function<_Tp, _Ret>
00624 {
00625 public:
00626 explicit
00627 mem_fun_ref_t(_Ret (_Tp::*__pf)())
00628 : _M_f(__pf) {}
00629
00630 _Ret
00631 operator()(_Tp& __r) const
00632 { return (__r.*_M_f)(); }
00633 private:
00634 _Ret (_Tp::*_M_f)();
00635 };
00636
00637
00638 template <class _Ret, class _Tp>
00639 class const_mem_fun_ref_t : public unary_function<_Tp, _Ret>
00640 {
00641 public:
00642 explicit
00643 const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const)
00644 : _M_f(__pf) {}
00645
00646 _Ret
00647 operator()(const _Tp& __r) const
00648 { return (__r.*_M_f)(); }
00649 private:
00650 _Ret (_Tp::*_M_f)() const;
00651 };
00652
00653
00654 template <class _Ret, class _Tp, class _Arg>
00655 class mem_fun1_t : public binary_function<_Tp*, _Arg, _Ret>
00656 {
00657 public:
00658 explicit
00659 mem_fun1_t(_Ret (_Tp::*__pf)(_Arg))
00660 : _M_f(__pf) {}
00661
00662 _Ret
00663 operator()(_Tp* __p, _Arg __x) const
00664 { return (__p->*_M_f)(__x); }
00665 private:
00666 _Ret (_Tp::*_M_f)(_Arg);
00667 };
00668
00669
00670 template <class _Ret, class _Tp, class _Arg>
00671 class const_mem_fun1_t : public binary_function<const _Tp*, _Arg, _Ret>
00672 {
00673 public:
00674 explicit
00675 const_mem_fun1_t(_Ret (_Tp::*__pf)(_Arg) const)
00676 : _M_f(__pf) {}
00677
00678 _Ret
00679 operator()(const _Tp* __p, _Arg __x) const
00680 { return (__p->*_M_f)(__x); }
00681 private:
00682 _Ret (_Tp::*_M_f)(_Arg) const;
00683 };
00684
00685
00686 template <class _Ret, class _Tp, class _Arg>
00687 class mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret>
00688 {
00689 public:
00690 explicit
00691 mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg))
00692 : _M_f(__pf) {}
00693
00694 _Ret
00695 operator()(_Tp& __r, _Arg __x) const
00696 { return (__r.*_M_f)(__x); }
00697 private:
00698 _Ret (_Tp::*_M_f)(_Arg);
00699 };
00700
00701
00702 template <class _Ret, class _Tp, class _Arg>
00703 class const_mem_fun1_ref_t : public binary_function<_Tp, _Arg, _Ret>
00704 {
00705 public:
00706 explicit
00707 const_mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg) const)
00708 : _M_f(__pf) {}
00709
00710 _Ret
00711 operator()(const _Tp& __r, _Arg __x) const
00712 { return (__r.*_M_f)(__x); }
00713 private:
00714 _Ret (_Tp::*_M_f)(_Arg) const;
00715 };
00716
00717
00718 template <class _Tp>
00719 class mem_fun_t<void, _Tp> : public unary_function<_Tp*, void>
00720 {
00721 public:
00722 explicit
00723 mem_fun_t(void (_Tp::*__pf)())
00724 : _M_f(__pf) {}
00725
00726 void
00727 operator()(_Tp* __p) const
00728 { (__p->*_M_f)(); }
00729 private:
00730 void (_Tp::*_M_f)();
00731 };
00732
00733
00734 template <class _Tp>
00735 class const_mem_fun_t<void, _Tp> : public unary_function<const _Tp*, void>
00736 {
00737 public:
00738 explicit
00739 const_mem_fun_t(void (_Tp::*__pf)() const)
00740 : _M_f(__pf) {}
00741
00742 void
00743 operator()(const _Tp* __p) const
00744 { (__p->*_M_f)(); }
00745 private:
00746 void (_Tp::*_M_f)() const;
00747 };
00748
00749
00750 template <class _Tp>
00751 class mem_fun_ref_t<void, _Tp> : public unary_function<_Tp, void>
00752 {
00753 public:
00754 explicit
00755 mem_fun_ref_t(void (_Tp::*__pf)())
00756 : _M_f(__pf) {}
00757
00758 void
00759 operator()(_Tp& __r) const
00760 { (__r.*_M_f)(); }
00761 private:
00762 void (_Tp::*_M_f)();
00763 };
00764
00765
00766 template <class _Tp>
00767 class const_mem_fun_ref_t<void, _Tp> : public unary_function<_Tp, void>
00768 {
00769 public:
00770 explicit
00771 const_mem_fun_ref_t(void (_Tp::*__pf)() const)
00772 : _M_f(__pf) {}
00773
00774 void
00775 operator()(const _Tp& __r) const
00776 { (__r.*_M_f)(); }
00777 private:
00778 void (_Tp::*_M_f)() const;
00779 };
00780
00781
00782 template <class _Tp, class _Arg>
00783 class mem_fun1_t<void, _Tp, _Arg> : public binary_function<_Tp*, _Arg, void>
00784 {
00785 public:
00786 explicit
00787 mem_fun1_t(void (_Tp::*__pf)(_Arg))
00788 : _M_f(__pf) {}
00789
00790 void
00791 operator()(_Tp* __p, _Arg __x) const
00792 { (__p->*_M_f)(__x); }
00793 private:
00794 void (_Tp::*_M_f)(_Arg);
00795 };
00796
00797
00798 template <class _Tp, class _Arg>
00799 class const_mem_fun1_t<void, _Tp, _Arg>
00800 : public binary_function<const _Tp*, _Arg, void>
00801 {
00802 public:
00803 explicit
00804 const_mem_fun1_t(void (_Tp::*__pf)(_Arg) const)
00805 : _M_f(__pf) {}
00806
00807 void
00808 operator()(const _Tp* __p, _Arg __x) const
00809 { (__p->*_M_f)(__x); }
00810 private:
00811 void (_Tp::*_M_f)(_Arg) const;
00812 };
00813
00814
00815 template <class _Tp, class _Arg>
00816 class mem_fun1_ref_t<void, _Tp, _Arg>
00817 : public binary_function<_Tp, _Arg, void>
00818 {
00819 public:
00820 explicit
00821 mem_fun1_ref_t(void (_Tp::*__pf)(_Arg))
00822 : _M_f(__pf) {}
00823
00824 void
00825 operator()(_Tp& __r, _Arg __x) const
00826 { (__r.*_M_f)(__x); }
00827 private:
00828 void (_Tp::*_M_f)(_Arg);
00829 };
00830
00831
00832 template <class _Tp, class _Arg>
00833 class const_mem_fun1_ref_t<void, _Tp, _Arg>
00834 : public binary_function<_Tp, _Arg, void>
00835 {
00836 public:
00837 explicit
00838 const_mem_fun1_ref_t(void (_Tp::*__pf)(_Arg) const)
00839 : _M_f(__pf) {}
00840
00841 void
00842 operator()(const _Tp& __r, _Arg __x) const
00843 { (__r.*_M_f)(__x); }
00844 private:
00845 void (_Tp::*_M_f)(_Arg) const;
00846 };
00847
00848
00849
00850 template <class _Ret, class _Tp>
00851 inline mem_fun_t<_Ret, _Tp>
00852 mem_fun(_Ret (_Tp::*__f)())
00853 { return mem_fun_t<_Ret, _Tp>(__f); }
00854
00855 template <class _Ret, class _Tp>
00856 inline const_mem_fun_t<_Ret, _Tp>
00857 mem_fun(_Ret (_Tp::*__f)() const)
00858 { return const_mem_fun_t<_Ret, _Tp>(__f); }
00859
00860 template <class _Ret, class _Tp>
00861 inline mem_fun_ref_t<_Ret, _Tp>
00862 mem_fun_ref(_Ret (_Tp::*__f)())
00863 { return mem_fun_ref_t<_Ret, _Tp>(__f); }
00864
00865 template <class _Ret, class _Tp>
00866 inline const_mem_fun_ref_t<_Ret, _Tp>
00867 mem_fun_ref(_Ret (_Tp::*__f)() const)
00868 { return const_mem_fun_ref_t<_Ret, _Tp>(__f); }
00869
00870 template <class _Ret, class _Tp, class _Arg>
00871 inline mem_fun1_t<_Ret, _Tp, _Arg>
00872 mem_fun(_Ret (_Tp::*__f)(_Arg))
00873 { return mem_fun1_t<_Ret, _Tp, _Arg>(__f); }
00874
00875 template <class _Ret, class _Tp, class _Arg>
00876 inline const_mem_fun1_t<_Ret, _Tp, _Arg>
00877 mem_fun(_Ret (_Tp::*__f)(_Arg) const)
00878 { return const_mem_fun1_t<_Ret, _Tp, _Arg>(__f); }
00879
00880 template <class _Ret, class _Tp, class _Arg>
00881 inline mem_fun1_ref_t<_Ret, _Tp, _Arg>
00882 mem_fun_ref(_Ret (_Tp::*__f)(_Arg))
00883 { return mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); }
00884
00885 template <class _Ret, class _Tp, class _Arg>
00886 inline const_mem_fun1_ref_t<_Ret, _Tp, _Arg>
00887 mem_fun_ref(_Ret (_Tp::*__f)(_Arg) const)
00888 { return const_mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); }
00889
00890
00891
00892 }
00893
00894 #endif
00895
00896
00897
00898