1 /* 2 * 3 * Copyright (c) 1994 4 * Hewlett-Packard Company 5 * 6 * Copyright (c) 1996-1998 7 * Silicon Graphics Computer Systems, Inc. 8 * 9 * Copyright (c) 1997 10 * Moscow Center for SPARC Technology 11 * 12 * Copyright (c) 1999 13 * Boris Fomitchev 14 * 15 * Copyright (c) 2000 16 * Pavel Kuznetsov 17 * 18 * Copyright (c) 2001 19 * Meridian'93 20 * 21 * This material is provided "as is", with absolutely no warranty expressed 22 * or implied. Any use is at your own risk. 23 * 24 * Permission to use or copy this software for any purpose is hereby granted 25 * without fee, provided the above notices are retained on all copies. 26 * Permission to modify the code and to distribute modified code is granted, 27 * provided the above notices are retained, and a notice that the code was 28 * modified is included with the above copyright notice. 29 * 30 */ 31 32 /* NOTE: This is an internal header file, included by other STL headers. 33 * You should not attempt to use it directly. 34 */ 35 36 // This file has noo macro protection as it is meant to be included several times 37 // from other header. 38 // Adaptor function objects: pointers to member functions. 39 40 // There are a total of 16 = 2^4 function objects in this family. 41 // (1) Member functions taking no arguments vs member functions taking 42 // one argument. 43 // (2) Call through pointer vs call through reference. 44 // (3) Member function with void return type vs member function with 45 // non-void return type. 46 // (4) Const vs non-const member function. 47 48 // Note that choice (3) is nothing more than a workaround: according 49 // to the draft, compilers should handle void and non-void the same way. 50 // This feature is not yet widely implemented, though. You can only use 51 // member functions returning void if your compiler supports partial 52 // specialization. 53 54 // All of this complexity is in the function objects themselves. You can 55 // ignore it by using the helper function mem_fun and mem_fun_ref, 56 // which create whichever type of adaptor is appropriate. 57 58 _STLP_BEGIN_NAMESPACE 59 60 //This implementation will only be used if needed, that is to say when there is the return void bug 61 //and when there is no partial template specialization 62 #if defined (_STLP_DONT_RETURN_VOID) && defined (_STLP_NO_CLASS_PARTIAL_SPECIALIZATION) && defined (_STLP_MEMBER_TEMPLATE_CLASSES) 63 64 template<class _Result, class _Tp> 65 class _Mem_fun0_ptr : public unary_function<_Tp*, _Result> { 66 protected: 67 typedef _Result (_Tp::*__fun_type) (); _Mem_fun0_ptr(__fun_type __f)68 explicit _Mem_fun0_ptr(__fun_type __f) : _M_f(__f) {} 69 70 public: operator()71 _Result operator ()(_Tp* __p) const { return (__p->*_M_f)(); } 72 73 private: 74 __fun_type _M_f; 75 }; 76 77 template<class _Result, class _Tp, class _Arg> 78 class _Mem_fun1_ptr : public binary_function<_Tp*,_Arg,_Result> { 79 protected: 80 typedef _Result (_Tp::*__fun_type) (_Arg); _Mem_fun1_ptr(__fun_type __f)81 explicit _Mem_fun1_ptr(__fun_type __f) : _M_f(__f) {} 82 83 public: operator()84 _Result operator ()(_Tp* __p, _Arg __x) const { return (__p->*_M_f)(__x); } 85 86 private: 87 __fun_type _M_f; 88 }; 89 90 template<class _Result, class _Tp> 91 class _Const_mem_fun0_ptr : public unary_function<const _Tp*,_Result> { 92 protected: 93 typedef _Result (_Tp::*__fun_type) () const; _Const_mem_fun0_ptr(__fun_type __f)94 explicit _Const_mem_fun0_ptr(__fun_type __f) : _M_f(__f) {} 95 96 public: operator()97 _Result operator ()(const _Tp* __p) const { return (__p->*_M_f)(); } 98 99 private: 100 __fun_type _M_f; 101 }; 102 103 template<class _Result, class _Tp, class _Arg> 104 class _Const_mem_fun1_ptr : public binary_function<const _Tp*,_Arg,_Result> { 105 protected: 106 typedef _Result (_Tp::*__fun_type) (_Arg) const; _Const_mem_fun1_ptr(__fun_type __f)107 explicit _Const_mem_fun1_ptr(__fun_type __f) : _M_f(__f) {} 108 109 public: operator()110 _Result operator ()(const _Tp* __p, _Arg __x) const { 111 return (__p->*_M_f)(__x); } 112 113 private: 114 __fun_type _M_f; 115 }; 116 117 template<class _Result, class _Tp> 118 class _Mem_fun0_ref : public unary_function<_Tp,_Result> { 119 protected: 120 typedef _Result (_Tp::*__fun_type) (); _Mem_fun0_ref(__fun_type __f)121 explicit _Mem_fun0_ref(__fun_type __f) : _M_f(__f) {} 122 123 public: operator()124 _Result operator ()(_Tp& __p) const { return (__p.*_M_f)(); } 125 126 private: 127 __fun_type _M_f; 128 }; 129 130 template<class _Result, class _Tp, class _Arg> 131 class _Mem_fun1_ref : public binary_function<_Tp,_Arg,_Result> { 132 protected: 133 typedef _Result (_Tp::*__fun_type) (_Arg); _Mem_fun1_ref(__fun_type __f)134 explicit _Mem_fun1_ref(__fun_type __f) : _M_f(__f) {} 135 136 public: operator()137 _Result operator ()(_Tp& __p, _Arg __x) const { return (__p.*_M_f)(__x); } 138 139 private: 140 __fun_type _M_f; 141 }; 142 143 template<class _Result, class _Tp> 144 class _Const_mem_fun0_ref : public unary_function<_Tp,_Result> { 145 protected: 146 typedef _Result (_Tp::*__fun_type) () const; _Const_mem_fun0_ref(__fun_type __f)147 explicit _Const_mem_fun0_ref(__fun_type __f) : _M_f(__f) {} 148 149 public: operator()150 _Result operator ()(const _Tp& __p) const { return (__p.*_M_f)(); } 151 152 private: 153 __fun_type _M_f; 154 }; 155 156 template<class _Result, class _Tp, class _Arg> 157 class _Const_mem_fun1_ref : public binary_function<_Tp,_Arg,_Result> { 158 protected: 159 typedef _Result (_Tp::*__fun_type) (_Arg) const; _Const_mem_fun1_ref(__fun_type __f)160 explicit _Const_mem_fun1_ref(__fun_type __f) : _M_f(__f) {} 161 162 public: operator()163 _Result operator ()(const _Tp& __p, _Arg __x) const { return (__p.*_M_f)(__x); } 164 165 private: 166 __fun_type _M_f; 167 }; 168 169 template<class _Result> 170 struct _Mem_fun_traits { 171 template<class _Tp> 172 struct _Args0 { 173 typedef _Mem_fun0_ptr<_Result,_Tp> _Ptr; 174 typedef _Const_mem_fun0_ptr<_Result,_Tp> _Ptr_const; 175 typedef _Mem_fun0_ref<_Result,_Tp> _Ref; 176 typedef _Const_mem_fun0_ref<_Result,_Tp> _Ref_const; 177 }; 178 179 template<class _Tp, class _Arg> 180 struct _Args1 { 181 typedef _Mem_fun1_ptr<_Result,_Tp,_Arg> _Ptr; 182 typedef _Const_mem_fun1_ptr<_Result,_Tp,_Arg> _Ptr_const; 183 typedef _Mem_fun1_ref<_Result,_Tp,_Arg> _Ref; 184 typedef _Const_mem_fun1_ref<_Result,_Tp,_Arg> _Ref_const; 185 }; 186 }; 187 188 template<class _Arg, class _Result> 189 class _Ptr_fun1_base : public unary_function<_Arg, _Result> { 190 protected: 191 typedef _Result (*__fun_type) (_Arg); _Ptr_fun1_base(__fun_type __f)192 explicit _Ptr_fun1_base(__fun_type __f) : _M_f(__f) {} 193 194 public: operator()195 _Result operator()(_Arg __x) const { return _M_f(__x); } 196 197 private: 198 __fun_type _M_f; 199 }; 200 201 template <class _Arg1, class _Arg2, class _Result> 202 class _Ptr_fun2_base : public binary_function<_Arg1,_Arg2,_Result> { 203 protected: 204 typedef _Result (*__fun_type) (_Arg1, _Arg2); _Ptr_fun2_base(__fun_type __f)205 explicit _Ptr_fun2_base(__fun_type __f) : _M_f(__f) {} 206 207 public: operator()208 _Result operator()(_Arg1 __x, _Arg2 __y) const { return _M_f(__x, __y); } 209 210 private: 211 __fun_type _M_f; 212 }; 213 214 template<class _Result> 215 struct _Ptr_fun_traits { 216 template<class _Arg> struct _Args1 { 217 typedef _Ptr_fun1_base<_Arg,_Result> _Fun; 218 }; 219 220 template<class _Arg1, class _Arg2> struct _Args2 { 221 typedef _Ptr_fun2_base<_Arg1,_Arg2,_Result> _Fun; 222 }; 223 }; 224 225 /* Specializations for void return type */ 226 template<class _Tp> 227 class _Void_mem_fun0_ptr : public unary_function<_Tp*,void> { 228 protected: 229 typedef void (_Tp::*__fun_type) (); _Void_mem_fun0_ptr(__fun_type __f)230 explicit _Void_mem_fun0_ptr(__fun_type __f) : _M_f(__f) {} 231 232 public: operator()233 void operator ()(_Tp* __p) const { (__p->*_M_f)(); } 234 235 private: 236 __fun_type _M_f; 237 }; 238 239 template<class _Tp, class _Arg> 240 class _Void_mem_fun1_ptr : public binary_function<_Tp*,_Arg,void> { 241 protected: 242 typedef void (_Tp::*__fun_type) (_Arg); _Void_mem_fun1_ptr(__fun_type __f)243 explicit _Void_mem_fun1_ptr(__fun_type __f) : _M_f(__f) {} 244 245 public: operator()246 void operator ()(_Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); } 247 248 private: 249 __fun_type _M_f; 250 }; 251 252 template<class _Tp> 253 class _Void_const_mem_fun0_ptr : public unary_function<const _Tp*,void> { 254 protected: 255 typedef void (_Tp::*__fun_type) () const; _Void_const_mem_fun0_ptr(__fun_type __f)256 explicit _Void_const_mem_fun0_ptr(__fun_type __f) : _M_f(__f) {} 257 258 public: operator()259 void operator ()(const _Tp* __p) const { (__p->*_M_f)(); } 260 261 private: 262 __fun_type _M_f; 263 }; 264 265 template<class _Tp, class _Arg> 266 class _Void_const_mem_fun1_ptr : public binary_function<const _Tp*,_Arg,void> { 267 protected: 268 typedef void (_Tp::*__fun_type) (_Arg) const; _Void_const_mem_fun1_ptr(__fun_type __f)269 explicit _Void_const_mem_fun1_ptr(__fun_type __f) : _M_f(__f) {} 270 271 public: operator()272 void operator ()(const _Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); } 273 274 private: 275 __fun_type _M_f; 276 }; 277 278 template<class _Tp> 279 class _Void_mem_fun0_ref : public unary_function<_Tp,void> { 280 protected: 281 typedef void (_Tp::*__fun_type) (); _Void_mem_fun0_ref(__fun_type __f)282 explicit _Void_mem_fun0_ref(__fun_type __f) : _M_f(__f) {} 283 284 public: operator()285 void operator ()(_Tp& __p) const { (__p.*_M_f)(); } 286 287 private: 288 __fun_type _M_f; 289 }; 290 291 template<class _Tp, class _Arg> 292 class _Void_mem_fun1_ref : public binary_function<_Tp,_Arg,void> { 293 protected: 294 typedef void (_Tp::*__fun_type) (_Arg); _Void_mem_fun1_ref(__fun_type __f)295 explicit _Void_mem_fun1_ref(__fun_type __f) : _M_f(__f) {} 296 297 public: operator()298 void operator ()(_Tp& __p, _Arg __x) const { (__p.*_M_f)(__x); } 299 300 private: 301 __fun_type _M_f; 302 }; 303 304 template<class _Tp> 305 class _Void_const_mem_fun0_ref : public unary_function<_Tp,void> { 306 protected: 307 typedef void (_Tp::*__fun_type) () const; _Void_const_mem_fun0_ref(__fun_type __f)308 explicit _Void_const_mem_fun0_ref(__fun_type __f) : _M_f(__f) {} 309 310 public: operator()311 void operator ()(const _Tp& __p) const { (__p.*_M_f)(); } 312 313 private: 314 __fun_type _M_f; 315 }; 316 317 template<class _Tp, class _Arg> 318 class _Void_const_mem_fun1_ref : public binary_function<_Tp,_Arg,void> { 319 protected: 320 typedef void (_Tp::*__fun_type) (_Arg) const; _Void_const_mem_fun1_ref(__fun_type __f)321 explicit _Void_const_mem_fun1_ref(__fun_type __f) : _M_f(__f) {} 322 323 public: operator()324 void operator ()(const _Tp& __p, _Arg __x) const { (__p.*_M_f)(__x); } 325 326 private: 327 __fun_type _M_f; 328 }; 329 330 _STLP_TEMPLATE_NULL 331 struct _Mem_fun_traits<void> { 332 template<class _Tp> struct _Args0 { 333 typedef _Void_mem_fun0_ptr<_Tp> _Ptr; 334 typedef _Void_const_mem_fun0_ptr<_Tp> _Ptr_const; 335 typedef _Void_mem_fun0_ref<_Tp> _Ref; 336 typedef _Void_const_mem_fun0_ref<_Tp> _Ref_const; 337 }; 338 339 template<class _Tp, class _Arg> struct _Args1 { 340 typedef _Void_mem_fun1_ptr<_Tp,_Arg> _Ptr; 341 typedef _Void_const_mem_fun1_ptr<_Tp,_Arg> _Ptr_const; 342 typedef _Void_mem_fun1_ref<_Tp,_Arg> _Ref; 343 typedef _Void_const_mem_fun1_ref<_Tp,_Arg> _Ref_const; 344 }; 345 }; 346 347 template<class _Arg> 348 class _Ptr_void_fun1_base : public unary_function<_Arg, void> { 349 protected: 350 typedef void (*__fun_type) (_Arg); 351 explicit _Ptr_void_fun1_base(__fun_type __f) : _M_f(__f) {} 352 353 public: 354 void operator()(_Arg __x) const { _M_f(__x); } 355 356 private: 357 __fun_type _M_f; 358 }; 359 360 template <class _Arg1, class _Arg2> 361 class _Ptr_void_fun2_base : public binary_function<_Arg1,_Arg2,void> { 362 protected: 363 typedef void (*__fun_type) (_Arg1, _Arg2); 364 explicit _Ptr_void_fun2_base(__fun_type __f) : _M_f(__f) {} 365 366 public: 367 void operator()(_Arg1 __x, _Arg2 __y) const { _M_f(__x, __y); } 368 369 private: 370 __fun_type _M_f; 371 }; 372 373 _STLP_TEMPLATE_NULL 374 struct _Ptr_fun_traits<void> { 375 template<class _Arg> struct _Args1 { 376 typedef _Ptr_void_fun1_base<_Arg> _Fun; 377 }; 378 379 template<class _Arg1, class _Arg2> struct _Args2 { 380 typedef _Ptr_void_fun2_base<_Arg1,_Arg2> _Fun; 381 }; 382 }; 383 384 // pavel: need extra level of inheritance here since MSVC++ does not 385 // accept traits-based fake partial specialization for template 386 // arguments other than first 387 388 template<class _Result, class _Arg> 389 class _Ptr_fun1 : 390 public _Ptr_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Arg>::_Fun { 391 protected: 392 typedef typename _Ptr_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Arg>::_Fun _Base; 393 explicit _Ptr_fun1(typename _Base::__fun_type __f) : _Base(__f) {} 394 }; 395 396 template<class _Result, class _Arg1, class _Arg2> 397 class _Ptr_fun2 : 398 public _Ptr_fun_traits<_Result>::_STLP_TEMPLATE _Args2<_Arg1,_Arg2>::_Fun { 399 protected: 400 typedef typename _Ptr_fun_traits<_Result>::_STLP_TEMPLATE _Args2<_Arg1,_Arg2>::_Fun _Base; 401 explicit _Ptr_fun2(typename _Base::__fun_type __f) : _Base(__f) {} 402 }; 403 404 template <class _Result, class _Tp> 405 class mem_fun_t : 406 public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ptr { 407 typedef typename 408 _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ptr _Base; 409 public: 410 explicit mem_fun_t(typename _Base::__fun_type __f) : _Base(__f) {} 411 }; 412 413 template <class _Result, class _Tp> 414 class const_mem_fun_t : 415 public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ptr_const { 416 typedef typename 417 _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ptr_const _Base; 418 public: 419 explicit const_mem_fun_t(typename _Base::__fun_type __f) : _Base(__f) {} 420 }; 421 422 template <class _Result, class _Tp> 423 class mem_fun_ref_t : 424 public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ref { 425 typedef typename 426 _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ref _Base; 427 public: 428 explicit mem_fun_ref_t(typename _Base::__fun_type __f) : _Base(__f) {} 429 }; 430 431 template <class _Result, class _Tp> 432 class const_mem_fun_ref_t : 433 public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ref_const { 434 typedef typename 435 _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args0<_Tp>::_Ref_const _Base; 436 public: 437 explicit const_mem_fun_ref_t(typename _Base::__fun_type __f) : _Base(__f) {} 438 }; 439 440 template <class _Result, class _Tp, class _Arg> 441 class mem_fun1_t : 442 public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ptr { 443 typedef typename 444 _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ptr _Base; 445 public: 446 explicit mem_fun1_t(typename _Base::__fun_type __f) : _Base(__f) {} 447 }; 448 449 template <class _Result, class _Tp, class _Arg> 450 class const_mem_fun1_t : 451 public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ptr_const { 452 typedef typename 453 _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ptr_const _Base; 454 public: 455 explicit const_mem_fun1_t(typename _Base::__fun_type __f) : _Base(__f) {} 456 }; 457 458 template <class _Result, class _Tp, class _Arg> 459 class mem_fun1_ref_t : 460 public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ref { 461 typedef typename 462 _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ref _Base; 463 public: 464 explicit mem_fun1_ref_t(typename _Base::__fun_type __f) : _Base(__f) {} 465 }; 466 467 template <class _Result, class _Tp, class _Arg> 468 class const_mem_fun1_ref_t : 469 public _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ref_const { 470 typedef typename 471 _Mem_fun_traits<_Result>::_STLP_TEMPLATE _Args1<_Tp,_Arg>::_Ref_const _Base; 472 public: 473 explicit const_mem_fun1_ref_t(typename _Base::__fun_type __f) : _Base(__f) {} 474 }; 475 476 template <class _Arg, class _Result> 477 class pointer_to_unary_function : 478 public _Ptr_fun1<_Result,_Arg> { 479 typedef typename 480 _Ptr_fun1<_Result,_Arg>::__fun_type __fun_type; 481 public: 482 explicit pointer_to_unary_function(__fun_type __f) 483 : _Ptr_fun1<_Result,_Arg>(__f) {} 484 }; 485 486 template <class _Arg1, class _Arg2, class _Result> 487 class pointer_to_binary_function : 488 public _Ptr_fun2<_Result,_Arg1,_Arg2> { 489 typedef typename 490 _Ptr_fun2<_Result,_Arg1,_Arg2>::__fun_type __fun_type; 491 public: 492 explicit pointer_to_binary_function(__fun_type __f) 493 : _Ptr_fun2<_Result,_Arg1,_Arg2>(__f) {} 494 }; 495 496 #else 497 498 template <class _Ret, class _Tp> 499 class mem_fun_t : public unary_function<_Tp*,_Ret> { 500 typedef _Ret (_Tp::*__fun_type)(void); 501 public: 502 explicit mem_fun_t(__fun_type __pf) : _M_f(__pf) {} 503 _Ret operator()(_Tp* __p) const { return (__p->*_M_f)(); } 504 private: 505 __fun_type _M_f; 506 }; 507 508 template <class _Ret, class _Tp> 509 class const_mem_fun_t : public unary_function<const _Tp*,_Ret> { 510 typedef _Ret (_Tp::*__fun_type)(void) const; 511 public: 512 explicit const_mem_fun_t(__fun_type __pf) : _M_f(__pf) {} 513 _Ret operator()(const _Tp* __p) const { return (__p->*_M_f)(); } 514 private: 515 __fun_type _M_f; 516 }; 517 518 template <class _Ret, class _Tp> 519 class mem_fun_ref_t : public unary_function<_Tp,_Ret> { 520 typedef _Ret (_Tp::*__fun_type)(void); 521 public: 522 explicit mem_fun_ref_t(__fun_type __pf) : _M_f(__pf) {} 523 _Ret operator()(_Tp& __r) const { return (__r.*_M_f)(); } 524 private: 525 __fun_type _M_f; 526 }; 527 528 template <class _Ret, class _Tp> 529 class const_mem_fun_ref_t : public unary_function<_Tp,_Ret> { 530 typedef _Ret (_Tp::*__fun_type)(void) const; 531 public: 532 explicit const_mem_fun_ref_t(__fun_type __pf) : _M_f(__pf) {} 533 _Ret operator()(const _Tp& __r) const { return (__r.*_M_f)(); } 534 private: 535 __fun_type _M_f; 536 }; 537 538 template <class _Ret, class _Tp, class _Arg> 539 class mem_fun1_t : public binary_function<_Tp*,_Arg,_Ret> { 540 typedef _Ret (_Tp::*__fun_type)(_Arg); 541 public: 542 explicit mem_fun1_t(__fun_type __pf) : _M_f(__pf) {} 543 _Ret operator()(_Tp* __p, _Arg __x) const { return (__p->*_M_f)(__x); } 544 private: 545 __fun_type _M_f; 546 }; 547 548 template <class _Ret, class _Tp, class _Arg> 549 class const_mem_fun1_t : public binary_function<const _Tp*,_Arg,_Ret> { 550 typedef _Ret (_Tp::*__fun_type)(_Arg) const; 551 public: 552 explicit const_mem_fun1_t(__fun_type __pf) : _M_f(__pf) {} 553 _Ret operator()(const _Tp* __p, _Arg __x) const 554 { return (__p->*_M_f)(__x); } 555 private: 556 __fun_type _M_f; 557 }; 558 559 template <class _Ret, class _Tp, class _Arg> 560 class mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> { 561 typedef _Ret (_Tp::*__fun_type)(_Arg); 562 public: 563 explicit mem_fun1_ref_t(__fun_type __pf) : _M_f(__pf) {} 564 _Ret operator()(_Tp& __r, _Arg __x) const { return (__r.*_M_f)(__x); } 565 private: 566 __fun_type _M_f; 567 }; 568 569 template <class _Ret, class _Tp, class _Arg> 570 class const_mem_fun1_ref_t : public binary_function<_Tp,_Arg,_Ret> { 571 typedef _Ret (_Tp::*__fun_type)(_Arg) const; 572 public: 573 explicit const_mem_fun1_ref_t(__fun_type __pf) : _M_f(__pf) {} 574 _Ret operator()(const _Tp& __r, _Arg __x) const { return (__r.*_M_f)(__x); } 575 private: 576 __fun_type _M_f; 577 }; 578 579 template <class _Arg, class _Result> 580 class pointer_to_unary_function : public unary_function<_Arg, _Result> { 581 protected: 582 _Result (*_M_ptr)(_Arg); 583 public: 584 pointer_to_unary_function() {} 585 explicit pointer_to_unary_function(_Result (*__x)(_Arg)) : _M_ptr(__x) {} 586 _Result operator()(_Arg __x) const { return _M_ptr(__x); } 587 }; 588 589 template <class _Arg1, class _Arg2, class _Result> 590 class pointer_to_binary_function : 591 public binary_function<_Arg1,_Arg2,_Result> { 592 protected: 593 _Result (*_M_ptr)(_Arg1, _Arg2); 594 public: 595 pointer_to_binary_function() {} 596 explicit pointer_to_binary_function(_Result (*__x)(_Arg1, _Arg2)) 597 : _M_ptr(__x) {} 598 _Result operator()(_Arg1 __x, _Arg2 __y) const { 599 return _M_ptr(__x, __y); 600 } 601 }; 602 603 # if defined (_STLP_DONT_RETURN_VOID) && !defined (_STLP_NO_CLASS_PARTIAL_SPECIALIZATION) 604 //Partial specializations for the void type 605 template <class _Tp> 606 class mem_fun_t<void, _Tp> : public unary_function<_Tp*,void> { 607 typedef void (_Tp::*__fun_type)(void); 608 public: 609 explicit mem_fun_t _STLP_PSPEC2(void,_Tp) (__fun_type __pf) : _M_f(__pf) {} 610 void operator()(_Tp* __p) const { (__p->*_M_f)(); } 611 private: 612 __fun_type _M_f; 613 }; 614 615 template <class _Tp> 616 class const_mem_fun_t<void, _Tp> : public unary_function<const _Tp*,void> { 617 typedef void (_Tp::*__fun_type)(void) const; 618 public: 619 explicit const_mem_fun_t _STLP_PSPEC2(void,_Tp) (__fun_type __pf) : _M_f(__pf) {} 620 void operator()(const _Tp* __p) const { (__p->*_M_f)(); } 621 private: 622 __fun_type _M_f; 623 }; 624 625 template <class _Tp> 626 class mem_fun_ref_t<void, _Tp> : public unary_function<_Tp,void> { 627 typedef void (_Tp::*__fun_type)(void); 628 public: 629 explicit mem_fun_ref_t _STLP_PSPEC2(void,_Tp) (__fun_type __pf) : _M_f(__pf) {} 630 void operator()(_Tp& __r) const { (__r.*_M_f)(); } 631 private: 632 __fun_type _M_f; 633 }; 634 635 template <class _Tp> 636 class const_mem_fun_ref_t<void, _Tp> : public unary_function<_Tp,void> { 637 typedef void (_Tp::*__fun_type)(void) const; 638 public: 639 explicit const_mem_fun_ref_t _STLP_PSPEC2(void,_Tp) (__fun_type __pf) : _M_f(__pf) {} 640 void operator()(const _Tp& __r) const { (__r.*_M_f)(); } 641 private: 642 __fun_type _M_f; 643 }; 644 645 template <class _Tp, class _Arg> 646 class mem_fun1_t<void, _Tp, _Arg> : public binary_function<_Tp*,_Arg,void> { 647 typedef void (_Tp::*__fun_type)(_Arg); 648 public: 649 explicit mem_fun1_t _STLP_PSPEC3(void,_Tp,_Arg) (__fun_type __pf) : _M_f(__pf) {} 650 void operator()(_Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); } 651 private: 652 __fun_type _M_f; 653 }; 654 655 template <class _Tp, class _Arg> 656 class const_mem_fun1_t<void, _Tp, _Arg> 657 : public binary_function<const _Tp*,_Arg,void> { 658 typedef void (_Tp::*__fun_type)(_Arg) const; 659 public: 660 explicit const_mem_fun1_t _STLP_PSPEC3(void,_Tp,_Arg) (__fun_type __pf) : _M_f(__pf) {} 661 void operator()(const _Tp* __p, _Arg __x) const { (__p->*_M_f)(__x); } 662 private: 663 __fun_type _M_f; 664 }; 665 666 template <class _Tp, class _Arg> 667 class mem_fun1_ref_t<void, _Tp, _Arg> 668 : public binary_function<_Tp,_Arg,void> { 669 typedef void (_Tp::*__fun_type)(_Arg); 670 public: 671 explicit mem_fun1_ref_t _STLP_PSPEC3(void,_Tp,_Arg) (__fun_type __pf) : _M_f(__pf) {} 672 void operator()(_Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); } 673 private: 674 __fun_type _M_f; 675 }; 676 677 template <class _Tp, class _Arg> 678 class const_mem_fun1_ref_t<void, _Tp, _Arg> 679 : public binary_function<_Tp,_Arg,void> { 680 typedef void (_Tp::*__fun_type)(_Arg) const; 681 public: 682 explicit const_mem_fun1_ref_t _STLP_PSPEC3(void,_Tp,_Arg) (__fun_type __pf) : _M_f(__pf) {} 683 void operator()(const _Tp& __r, _Arg __x) const { (__r.*_M_f)(__x); } 684 private: 685 __fun_type _M_f; 686 }; 687 688 template <class _Arg> 689 class pointer_to_unary_function<_Arg, void> : public unary_function<_Arg, void> { 690 typedef void (*__fun_type)(_Arg); 691 __fun_type _M_ptr; 692 public: 693 pointer_to_unary_function() {} 694 explicit pointer_to_unary_function(__fun_type __x) : _M_ptr(__x) {} 695 void operator()(_Arg __x) const { _M_ptr(__x); } 696 }; 697 698 template <class _Arg1, class _Arg2> 699 class pointer_to_binary_function<_Arg1, _Arg2, void> : public binary_function<_Arg1,_Arg2,void> { 700 typedef void (*__fun_type)(_Arg1, _Arg2); 701 __fun_type _M_ptr; 702 public: 703 pointer_to_binary_function() {} 704 explicit pointer_to_binary_function(__fun_type __x) : _M_ptr(__x) {} 705 void operator()(_Arg1 __x, _Arg2 __y) const { _M_ptr(__x, __y); } 706 }; 707 708 # endif 709 710 #endif 711 712 #if !defined (_STLP_MEMBER_POINTER_PARAM_BUG) 713 // Mem_fun adaptor helper functions. There are only two: 714 // mem_fun and mem_fun_ref. (mem_fun1 and mem_fun1_ref 715 // are provided for backward compatibility, but they are no longer 716 // part of the C++ standard.) 717 718 template <class _Result, class _Tp> 719 inline mem_fun_t<_Result,_Tp> 720 mem_fun(_Result (_Tp::*__f)()) { return mem_fun_t<_Result,_Tp>(__f); } 721 722 template <class _Result, class _Tp> 723 inline const_mem_fun_t<_Result,_Tp> 724 mem_fun(_Result (_Tp::*__f)() const) { return const_mem_fun_t<_Result,_Tp>(__f); } 725 726 template <class _Result, class _Tp> 727 inline mem_fun_ref_t<_Result,_Tp> 728 mem_fun_ref(_Result (_Tp::*__f)()) { return mem_fun_ref_t<_Result,_Tp>(__f); } 729 730 template <class _Result, class _Tp> 731 inline const_mem_fun_ref_t<_Result,_Tp> 732 mem_fun_ref(_Result (_Tp::*__f)() const) { return const_mem_fun_ref_t<_Result,_Tp>(__f); } 733 734 template <class _Result, class _Tp, class _Arg> 735 inline mem_fun1_t<_Result,_Tp,_Arg> 736 mem_fun(_Result (_Tp::*__f)(_Arg)) { return mem_fun1_t<_Result,_Tp,_Arg>(__f); } 737 738 template <class _Result, class _Tp, class _Arg> 739 inline const_mem_fun1_t<_Result,_Tp,_Arg> 740 mem_fun(_Result (_Tp::*__f)(_Arg) const) { return const_mem_fun1_t<_Result,_Tp,_Arg>(__f); } 741 742 template <class _Result, class _Tp, class _Arg> 743 inline mem_fun1_ref_t<_Result,_Tp,_Arg> 744 mem_fun_ref(_Result (_Tp::*__f)(_Arg)) { return mem_fun1_ref_t<_Result,_Tp,_Arg>(__f); } 745 746 template <class _Result, class _Tp, class _Arg> 747 inline const_mem_fun1_ref_t<_Result,_Tp,_Arg> 748 mem_fun_ref(_Result (_Tp::*__f)(_Arg) const) { return const_mem_fun1_ref_t<_Result,_Tp,_Arg>(__f); } 749 750 # if !(defined (_STLP_NO_EXTENSIONS) || defined (_STLP_NO_ANACHRONISMS)) 751 // mem_fun1 and mem_fun1_ref are no longer part of the C++ standard, 752 // but they are provided for backward compatibility. 753 template <class _Result, class _Tp, class _Arg> 754 inline mem_fun1_t<_Result,_Tp,_Arg> 755 mem_fun1(_Result (_Tp::*__f)(_Arg)) { return mem_fun1_t<_Result,_Tp,_Arg>(__f); } 756 757 template <class _Result, class _Tp, class _Arg> 758 inline const_mem_fun1_t<_Result,_Tp,_Arg> 759 mem_fun1(_Result (_Tp::*__f)(_Arg) const) { return const_mem_fun1_t<_Result,_Tp,_Arg>(__f); } 760 761 template <class _Result, class _Tp, class _Arg> 762 inline mem_fun1_ref_t<_Result,_Tp,_Arg> 763 mem_fun1_ref(_Result (_Tp::*__f)(_Arg)) { return mem_fun1_ref_t<_Result,_Tp,_Arg>(__f); } 764 765 template <class _Result, class _Tp, class _Arg> 766 inline const_mem_fun1_ref_t<_Result,_Tp,_Arg> 767 mem_fun1_ref(_Result (_Tp::*__f)(_Arg) const) { return const_mem_fun1_ref_t<_Result,_Tp,_Arg>(__f); } 768 769 # endif 770 771 #endif 772 773 template <class _Arg, class _Result> 774 inline pointer_to_unary_function<_Arg, _Result> 775 ptr_fun(_Result (*__f)(_Arg)) 776 { return pointer_to_unary_function<_Arg, _Result>(__f); } 777 778 template <class _Arg1, class _Arg2, class _Result> 779 inline pointer_to_binary_function<_Arg1,_Arg2,_Result> 780 ptr_fun(_Result (*__f)(_Arg1, _Arg2)) 781 { return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f); } 782 783 _STLP_END_NAMESPACE 784