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