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 __GLIBCPP_INTERNAL_FUNCTION_H
00062 #define __GLIBCPP_INTERNAL_FUNCTION_H
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 typedef _Arg argument_type;
00104 typedef _Result result_type;
00105 };
00106
00107
00108
00109
00110 template <class _Arg1, class _Arg2, class _Result>
00111 struct binary_function {
00112 typedef _Arg1 first_argument_type;
00113 typedef _Arg2 second_argument_type;
00114 typedef _Result result_type;
00115 };
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 template <class _Tp>
00128 struct plus : public binary_function<_Tp,_Tp,_Tp> {
00129 _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x + __y; }
00130 };
00131
00132
00133 template <class _Tp>
00134 struct minus : public binary_function<_Tp,_Tp,_Tp> {
00135 _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x - __y; }
00136 };
00137
00138
00139 template <class _Tp>
00140 struct multiplies : public binary_function<_Tp,_Tp,_Tp> {
00141 _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x * __y; }
00142 };
00143
00144
00145 template <class _Tp>
00146 struct divides : public binary_function<_Tp,_Tp,_Tp> {
00147 _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x / __y; }
00148 };
00149
00150
00151 template <class _Tp>
00152 struct modulus : public binary_function<_Tp,_Tp,_Tp>
00153 {
00154 _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x % __y; }
00155 };
00156
00157
00158 template <class _Tp>
00159 struct negate : public unary_function<_Tp,_Tp>
00160 {
00161 _Tp operator()(const _Tp& __x) const { return -__x; }
00162 };
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 template <class _Tp>
00174 struct equal_to : public binary_function<_Tp,_Tp,bool>
00175 {
00176 bool operator()(const _Tp& __x, const _Tp& __y) const { return __x == __y; }
00177 };
00178
00179
00180 template <class _Tp>
00181 struct not_equal_to : public binary_function<_Tp,_Tp,bool>
00182 {
00183 bool operator()(const _Tp& __x, const _Tp& __y) const { return __x != __y; }
00184 };
00185
00186
00187 template <class _Tp>
00188 struct greater : public binary_function<_Tp,_Tp,bool>
00189 {
00190 bool operator()(const _Tp& __x, const _Tp& __y) const { return __x > __y; }
00191 };
00192
00193
00194 template <class _Tp>
00195 struct less : public binary_function<_Tp,_Tp,bool>
00196 {
00197 bool operator()(const _Tp& __x, const _Tp& __y) const { return __x < __y; }
00198 };
00199
00200
00201 template <class _Tp>
00202 struct greater_equal : public binary_function<_Tp,_Tp,bool>
00203 {
00204 bool operator()(const _Tp& __x, const _Tp& __y) const { return __x >= __y; }
00205 };
00206
00207
00208 template <class _Tp>
00209 struct less_equal : public binary_function<_Tp,_Tp,bool>
00210 {
00211 bool operator()(const _Tp& __x, const _Tp& __y) const { return __x <= __y; }
00212 };
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222 template <class _Tp>
00223 struct logical_and : public binary_function<_Tp,_Tp,bool>
00224 {
00225 bool operator()(const _Tp& __x, const _Tp& __y) const { return __x && __y; }
00226 };
00227
00228
00229 template <class _Tp>
00230 struct logical_or : public binary_function<_Tp,_Tp,bool>
00231 {
00232 bool operator()(const _Tp& __x, const _Tp& __y) const { return __x || __y; }
00233 };
00234
00235
00236 template <class _Tp>
00237 struct logical_not : public unary_function<_Tp,bool>
00238 {
00239 bool operator()(const _Tp& __x) const { return !__x; }
00240 };
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271 template <class _Predicate>
00272 class unary_negate
00273 : public unary_function<typename _Predicate::argument_type, bool> {
00274 protected:
00275 _Predicate _M_pred;
00276 public:
00277 explicit unary_negate(const _Predicate& __x) : _M_pred(__x) {}
00278 bool operator()(const typename _Predicate::argument_type& __x) const {
00279 return !_M_pred(__x);
00280 }
00281 };
00282
00283
00284 template <class _Predicate>
00285 inline unary_negate<_Predicate>
00286 not1(const _Predicate& __pred)
00287 {
00288 return unary_negate<_Predicate>(__pred);
00289 }
00290
00291
00292 template <class _Predicate>
00293 class binary_negate
00294 : public binary_function<typename _Predicate::first_argument_type,
00295 typename _Predicate::second_argument_type,
00296 bool> {
00297 protected:
00298 _Predicate _M_pred;
00299 public:
00300 explicit binary_negate(const _Predicate& __x) : _M_pred(__x) {}
00301 bool operator()(const typename _Predicate::first_argument_type& __x,
00302 const typename _Predicate::second_argument_type& __y) const
00303 {
00304 return !_M_pred(__x, __y);
00305 }
00306 };
00307
00308
00309 template <class _Predicate>
00310 inline binary_negate<_Predicate>
00311 not2(const _Predicate& __pred)
00312 {
00313 return binary_negate<_Predicate>(__pred);
00314 }
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349 template <class _Operation>
00350 class binder1st
00351 : public unary_function<typename _Operation::second_argument_type,
00352 typename _Operation::result_type> {
00353 protected:
00354 _Operation op;
00355 typename _Operation::first_argument_type value;
00356 public:
00357 binder1st(const _Operation& __x,
00358 const typename _Operation::first_argument_type& __y)
00359 : op(__x), value(__y) {}
00360 typename _Operation::result_type
00361 operator()(const typename _Operation::second_argument_type& __x) const {
00362 return op(value, __x);
00363 }
00364 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00365
00366 typename _Operation::result_type
00367 operator()(typename _Operation::second_argument_type& __x) const {
00368 return op(value, __x);
00369 }
00370 #endif
00371 };
00372
00373
00374 template <class _Operation, class _Tp>
00375 inline binder1st<_Operation>
00376 bind1st(const _Operation& __fn, const _Tp& __x)
00377 {
00378 typedef typename _Operation::first_argument_type _Arg1_type;
00379 return binder1st<_Operation>(__fn, _Arg1_type(__x));
00380 }
00381
00382
00383 template <class _Operation>
00384 class binder2nd
00385 : public unary_function<typename _Operation::first_argument_type,
00386 typename _Operation::result_type> {
00387 protected:
00388 _Operation op;
00389 typename _Operation::second_argument_type value;
00390 public:
00391 binder2nd(const _Operation& __x,
00392 const typename _Operation::second_argument_type& __y)
00393 : op(__x), value(__y) {}
00394 typename _Operation::result_type
00395 operator()(const typename _Operation::first_argument_type& __x) const {
00396 return op(__x, value);
00397 }
00398 #ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS
00399
00400 typename _Operation::result_type
00401 operator()(typename _Operation::first_argument_type& __x) const {
00402 return op(__x, value);
00403 }
00404 #endif
00405 };
00406
00407
00408 template <class _Operation, class _Tp>
00409 inline binder2nd<_Operation>
00410 bind2nd(const _Operation& __fn, const _Tp& __x)
00411 {
00412 typedef typename _Operation::second_argument_type _Arg2_type;
00413 return binder2nd<_Operation>(__fn, _Arg2_type(__x));
00414 }
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438 template <class _Arg, class _Result>
00439 class pointer_to_unary_function : public unary_function<_Arg, _Result> {
00440 protected:
00441 _Result (*_M_ptr)(_Arg);
00442 public:
00443 pointer_to_unary_function() {}
00444 explicit pointer_to_unary_function(_Result (*__x)(_Arg)) : _M_ptr(__x) {}
00445 _Result operator()(_Arg __x) const { return _M_ptr(__x); }
00446 };
00447
00448
00449 template <class _Arg, class _Result>
00450 inline pointer_to_unary_function<_Arg, _Result> ptr_fun(_Result (*__x)(_Arg))
00451 {
00452 return pointer_to_unary_function<_Arg, _Result>(__x);
00453 }
00454
00455
00456 template <class _Arg1, class _Arg2, class _Result>
00457 class pointer_to_binary_function :
00458 public binary_function<_Arg1,_Arg2,_Result> {
00459 protected:
00460 _Result (*_M_ptr)(_Arg1, _Arg2);
00461 public:
00462 pointer_to_binary_function() {}
00463 explicit pointer_to_binary_function(_Result (*__x)(_Arg1, _Arg2))
00464 : _M_ptr(__x) {}
00465 _Result operator()(_Arg1 __x, _Arg2 __y) const {
00466 return _M_ptr(__x, __y);
00467 }
00468 };
00469
00470
00471 template <class _Arg1, class _Arg2, class _Result>
00472 inline pointer_to_binary_function<_Arg1,_Arg2,_Result>
00473 ptr_fun(_Result (*__x)(_Arg1, _Arg2)) {
00474 return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__x);
00475 }
00476
00477
00478 template <class _Tp>
00479 struct _Identity : public unary_function<_Tp,_Tp> {
00480 _Tp& operator()(_Tp& __x) const { return __x; }
00481 const _Tp& operator()(const _Tp& __x) const { return __x; }
00482 };
00483
00484 template <class _Pair>
00485 struct _Select1st : public unary_function<_Pair, typename _Pair::first_type> {
00486 typename _Pair::first_type& operator()(_Pair& __x) const {
00487 return __x.first;
00488 }
00489 const typename _Pair::first_type& operator()(const _Pair& __x) const {
00490 return __x.first;
00491 }
00492 };
00493
00494 template <class _Pair>
00495 struct _Select2nd : public unary_function<_Pair, typename _Pair::second_type>
00496 {
00497 typename _Pair::second_type& operator()(_Pair& __x) const {
00498 return __x.second;
00499 }
00500 const typename _Pair::second_type& operator()(const _Pair& __x) const {
00501 return __x.second;
00502 }
00503 };
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528 template <class _Ret, class _Tp>
00529 class mem_fun_t : public unary_function<_Tp*,_Ret> {
00530 public:
00531 explicit mem_fun_t(_Ret (_Tp::*__pf)()) : _M_f(__pf) {}
00532 _Ret operator()(_Tp* __p) const { return (__p->*_M_f)(); }
00533 private:
00534 _Ret (_Tp::*_M_f)();
00535 };
00536
00537
00538 template <class _Ret, class _Tp>
00539 class const_mem_fun_t : public unary_function<const _Tp*,_Ret> {
00540 public:
00541 explicit const_mem_fun_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}
00542 _Ret operator()(const _Tp* __p) const { return (__p->*_M_f)(); }
00543 private:
00544 _Ret (_Tp::*_M_f)() const;
00545 };
00546
00547
00548 template <class _Ret, class _Tp>
00549 class mem_fun_ref_t : public unary_function<_Tp,_Ret> {
00550 public:
00551 explicit mem_fun_ref_t(_Ret (_Tp::*__pf)()) : _M_f(__pf) {}
00552 _Ret operator()(_Tp& __r) const { return (__r.*_M_f)(); }
00553 private:
00554 _Ret (_Tp::*_M_f)();
00555 };
00556
00557
00558 template <class _Ret, class _Tp>
00559 class const_mem_fun_ref_t : public unary_function<_Tp,_Ret> {
00560 public:
00561 explicit const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const) : _M_f(__pf) {}
00562 _Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); }
00563 private:
00564 _Ret (_Tp::*_M_f)() const;
00565 };
00566
00567
00568 template <class _Ret, class _Tp, class _Arg>
00569 class mem_fun1_t : public binary_function<_Tp*,_Arg,_Ret> {
00570 public:
00571 explicit mem_fun1_t(_Ret (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}
00572 _Ret operator()(_Tp* __p, _Arg __x) const { return (__p->*_M_f)(__x); }
00573 private:
00574 _Ret (_Tp::*_M_f)(_Arg);
00575 };
00576
00577
00578 template <class _Ret, class _Tp, class _Arg>
00579 class const_mem_fun1_t : public binary_function<const _Tp*,_Arg,_Ret> {
00580 public:
00581 explicit const_mem_fun1_t(_Ret (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {}
00582 _Ret operator()(const _Tp* __p, _Arg __x) const
00583 { return (__p->*_M_f)(__x); }
00584 private:
00585 _Ret (_Tp::*_M_f)(_Arg) const;
00586 };
00587
00588
00589 template <class _Ret, class _Tp, class _Arg>
00590 class mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> {
00591 public:
00592 explicit mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}
00593 _Ret operator()(_Tp& __r, _Arg __x) const { return (__r.*_M_f)(__x); }
00594 private:
00595 _Ret (_Tp::*_M_f)(_Arg);
00596 };
00597
00598
00599 template <class _Ret, class _Tp, class _Arg>
00600 class const_mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> {
00601 public:
00602 explicit const_mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {}
00603 _Ret operator()(const _Tp& __r, _Arg __x) const { return (__r.*_M_f)(__x); }
00604 private:
00605 _Ret (_Tp::*_M_f)(_Arg) const;
00606 };
00607
00608
00609 template <class _Tp>
00610 class mem_fun_t<void, _Tp> : public unary_function<_Tp*,void> {
00611 public:
00612 explicit mem_fun_t(void (_Tp::*__pf)()) : _M_f(__pf) {}
00613 void operator()(_Tp* __p) const { (__p->*_M_f)(); }
00614 private:
00615 void (_Tp::*_M_f)();
00616 };
00617
00618
00619 template <class _Tp>
00620 class const_mem_fun_t<void, _Tp> : public unary_function<const _Tp*,void> {
00621 public:
00622 explicit const_mem_fun_t(void (_Tp::*__pf)() const) : _M_f(__pf) {}
00623 void operator()(const _Tp* __p) const { (__p->*_M_f)(); }
00624 private:
00625 void (_Tp::*_M_f)() const;
00626 };
00627
00628
00629 template <class _Tp>
00630 class mem_fun_ref_t<void, _Tp> : public unary_function<_Tp,void> {
00631 public:
00632 explicit mem_fun_ref_t(void (_Tp::*__pf)()) : _M_f(__pf) {}
00633 void operator()(_Tp& __r) const { (__r.*_M_f)(); }
00634 private:
00635 void (_Tp::*_M_f)();
00636 };
00637
00638
00639 template <class _Tp>
00640 class const_mem_fun_ref_t<void, _Tp> : public unary_function<_Tp,void> {
00641 public:
00642 explicit const_mem_fun_ref_t(void (_Tp::*__pf)() const) : _M_f(__pf) {}
00643 void operator()(const _Tp& __r) const { (__r.*_M_f)(); }
00644 private:
00645 void (_Tp::*_M_f)() const;
00646 };
00647
00648
00649 template <class _Tp, class _Arg>
00650 class mem_fun1_t<void, _Tp, _Arg> : public binary_function<_Tp*,_Arg,void> {
00651 public:
00652 explicit mem_fun1_t(void (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}
00653 void operator()(_Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }
00654 private:
00655 void (_Tp::*_M_f)(_Arg);
00656 };
00657
00658
00659 template <class _Tp, class _Arg>
00660 class const_mem_fun1_t<void, _Tp, _Arg>
00661 : public binary_function<const _Tp*,_Arg,void> {
00662 public:
00663 explicit const_mem_fun1_t(void (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {}
00664 void operator()(const _Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); }
00665 private:
00666 void (_Tp::*_M_f)(_Arg) const;
00667 };
00668
00669
00670 template <class _Tp, class _Arg>
00671 class mem_fun1_ref_t<void, _Tp, _Arg>
00672 : public binary_function<_Tp,_Arg,void> {
00673 public:
00674 explicit mem_fun1_ref_t(void (_Tp::*__pf)(_Arg)) : _M_f(__pf) {}
00675 void operator()(_Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); }
00676 private:
00677 void (_Tp::*_M_f)(_Arg);
00678 };
00679
00680
00681 template <class _Tp, class _Arg>
00682 class const_mem_fun1_ref_t<void, _Tp, _Arg>
00683 : public binary_function<_Tp,_Arg,void> {
00684 public:
00685 explicit const_mem_fun1_ref_t(void (_Tp::*__pf)(_Arg) const) : _M_f(__pf) {}
00686 void operator()(const _Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); }
00687 private:
00688 void (_Tp::*_M_f)(_Arg) const;
00689 };
00690
00691
00692
00693
00694
00695 template <class _Ret, class _Tp>
00696 inline mem_fun_t<_Ret,_Tp> mem_fun(_Ret (_Tp::*__f)())
00697 { return mem_fun_t<_Ret,_Tp>(__f); }
00698
00699 template <class _Ret, class _Tp>
00700 inline const_mem_fun_t<_Ret,_Tp> mem_fun(_Ret (_Tp::*__f)() const)
00701 { return const_mem_fun_t<_Ret,_Tp>(__f); }
00702
00703 template <class _Ret, class _Tp>
00704 inline mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)())
00705 { return mem_fun_ref_t<_Ret,_Tp>(__f); }
00706
00707 template <class _Ret, class _Tp>
00708 inline const_mem_fun_ref_t<_Ret,_Tp> mem_fun_ref(_Ret (_Tp::*__f)() const)
00709 { return const_mem_fun_ref_t<_Ret,_Tp>(__f); }
00710
00711 template <class _Ret, class _Tp, class _Arg>
00712 inline mem_fun1_t<_Ret,_Tp,_Arg> mem_fun(_Ret (_Tp::*__f)(_Arg))
00713 { return mem_fun1_t<_Ret,_Tp,_Arg>(__f); }
00714
00715 template <class _Ret, class _Tp, class _Arg>
00716 inline const_mem_fun1_t<_Ret,_Tp,_Arg> mem_fun(_Ret (_Tp::*__f)(_Arg) const)
00717 { return const_mem_fun1_t<_Ret,_Tp,_Arg>(__f); }
00718
00719 template <class _Ret, class _Tp, class _Arg>
00720 inline mem_fun1_ref_t<_Ret,_Tp,_Arg> mem_fun_ref(_Ret (_Tp::*__f)(_Arg))
00721 { return mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }
00722
00723 template <class _Ret, class _Tp, class _Arg>
00724 inline const_mem_fun1_ref_t<_Ret,_Tp,_Arg>
00725 mem_fun_ref(_Ret (_Tp::*__f)(_Arg) const)
00726 { return const_mem_fun1_ref_t<_Ret,_Tp,_Arg>(__f); }
00727
00728
00729
00730 }
00731
00732 #endif
00733
00734
00735
00736