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