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