| 349 |
|
public: |
| 350 |
|
explicit pointer_to_unary_function(_Fn _Left) |
| 351 |
|
: _Pfun(_Left) |
| 352 |
|
{ // construct from pointer |
| 353 |
|
} |
| 354 |
|
|
| 355 |
|
_Result operator()(_Arg _Left) const |
| 356 |
|
{ // call function with operand |
| 357 |
|
return (_Pfun(_Left)); |
| 358 |
|
} |
| 359 |
|
|
| 360 |
|
protected: |
| 361 |
|
_Fn _Pfun; // the function pointer |
| 362 |
|
}; |
| 363 |
|
|
| 364 |
|
// TEMPLATE CLASS pointer_to_binary_function |
| 365 |
|
template<class _Arg1, |
| 366 |
|
class _Arg2, |
| 367 |
|
class _Result, |
| 368 |
|
class _Fn = _Result (*)(_Arg1, _Arg2)> |
| 369 |
|
class pointer_to_binary_function |
| 370 |
|
: public binary_function<_Arg1, _Arg2, _Result> |
| 371 |
|
{ // functor adapter (*pfunc)(left, right) |
| 372 |
|
public: |
| 373 |
|
explicit pointer_to_binary_function(_Fn _Left) |
| 374 |
|
: _Pfun(_Left) |
| 375 |
|
{ // construct from pointer |
| 376 |
|
} |
| 377 |
|
|
| 378 |
|
_Result operator()(_Arg1 _Left, _Arg2 _Right) const |
| 379 |
|
{ // call function with operands |
| 380 |
|
return (_Pfun(_Left, _Right)); |
| 381 |
|
} |
| 382 |
|
|
| 383 |
|
protected: |
| 384 |
|
_Fn _Pfun; // the function pointer |
| 385 |
|
}; |
| 386 |
|
|
| 387 |
|
// TEMPLATE FUNCTION ptr_fun |
| 388 |
|
template<class _Arg, |
| 389 |
|
class _Result> inline |
| 390 |
|
pointer_to_unary_function<_Arg, _Result, |
| 391 |
|
_Result (__cdecl *)(_Arg)> |
| 392 |
|
ptr_fun(_Result (__cdecl *_Left)(_Arg)) |
| 393 |
|
{ // return pointer_to_unary_function functor adapter |
| 394 |
|
return (std::pointer_to_unary_function<_Arg, _Result, |
| 395 |
|
_Result (__cdecl *)(_Arg)>(_Left)); |
| 396 |
|
} |
| 397 |
|
|
| 398 |
|
#ifdef _M_IX86 |
| 399 |
|
template<class _Arg, |
| 400 |
|
class _Result> inline |
| 401 |
|
pointer_to_unary_function<_Arg, _Result, |
| 402 |
|
_Result (__stdcall *)(_Arg)> |
| 403 |
|
ptr_fun(_Result (__stdcall *_Left)(_Arg)) |
| 404 |
|
{ // return pointer_to_unary_function functor adapter |
| 405 |
|
return (std::pointer_to_unary_function<_Arg, _Result, |
| 406 |
|
_Result (__stdcall *)(_Arg)>(_Left)); |
| 407 |
|
} |
| 408 |
|
|
| 409 |
|
#ifndef _M_CEE |
| 410 |
|
template<class _Arg, |
| 411 |
|
class _Result> inline |
| 412 |
|
pointer_to_unary_function<_Arg, _Result, |
| 413 |
|
_Result (__fastcall *)(_Arg)> |
| 414 |
|
ptr_fun(_Result (__fastcall *_Left)(_Arg)) |
| 415 |
|
{ // return pointer_to_unary_function functor adapter |
| 416 |
|
return (std::pointer_to_unary_function<_Arg, _Result, |
| 417 |
|
_Result (__fastcall *)(_Arg)>(_Left)); |
| 418 |
|
} |
| 419 |
|
#endif /* _M_CEE */ |
| 420 |
|
#endif /* _M_IX86 */ |
| 421 |
|
|
| 422 |
|
#ifdef _M_CEE |
| 423 |
|
template<class _Arg, |
| 424 |
|
class _Result> inline |
| 425 |
|
pointer_to_unary_function<_Arg, _Result, |
| 426 |
|
_Result (__clrcall *)(_Arg)> |
| 427 |
|
ptr_fun(_Result (__clrcall *_Left)(_Arg)) |
| 428 |
|
{ // return pointer_to_unary_function functor adapter |
| 429 |
|
return (std::pointer_to_unary_function<_Arg, _Result, |
| 430 |
|
_Result (__clrcall *)(_Arg)>(_Left)); |
| 431 |
|
} |
| 432 |
|
#endif /* _M_CEE */ |
| 433 |
|
|
| 434 |
|
template<class _Arg1, |
| 435 |
|
class _Arg2, |
| 436 |
|
class _Result> inline |
| 437 |
|
pointer_to_binary_function<_Arg1, _Arg2, _Result, |
| 438 |
|
_Result(__cdecl *)(_Arg1, _Arg2)> |
| 439 |
|
ptr_fun(_Result (__cdecl *_Left)(_Arg1, _Arg2)) |
| 440 |
|
{ // return pointer_to_binary_function functor adapter |
| 441 |
|
return (std::pointer_to_binary_function<_Arg1, _Arg2, _Result, |
| 442 |
|
_Result (__cdecl *)(_Arg1, _Arg2)>(_Left)); |
| 443 |
|
} |
| 444 |
|
|
| 445 |
|
#ifdef _M_IX86 |
| 446 |
|
template<class _Arg1, |
| 447 |
|
class _Arg2, |
| 448 |
|
class _Result> inline |
| 449 |
|
pointer_to_binary_function<_Arg1, _Arg2, _Result, |
| 450 |
|
_Result(__stdcall *)(_Arg1, _Arg2)> |
| 451 |
|
ptr_fun(_Result (__stdcall *_Left)(_Arg1, _Arg2)) |
| 452 |
|
{ // return pointer_to_binary_function functor adapter |
| 453 |
|
return (std::pointer_to_binary_function<_Arg1, _Arg2, _Result, |
| 454 |
|
_Result (__stdcall *)(_Arg1, _Arg2)>(_Left)); |
| 455 |
|
} |
| 456 |
|
|
| 457 |
|
#ifndef _M_CEE |
| 458 |
|
template<class _Arg1, |
| 459 |
|
class _Arg2, |
| 460 |
|
class _Result> inline |
| 461 |
|
pointer_to_binary_function<_Arg1, _Arg2, _Result, |
| 462 |
|
_Result(__fastcall *)(_Arg1, _Arg2)> |
| 463 |
|
ptr_fun(_Result (__fastcall *_Left)(_Arg1, _Arg2)) |
| 464 |
|
{ // return pointer_to_binary_function functor adapter |
| 465 |
|
return (std::pointer_to_binary_function<_Arg1, _Arg2, _Result, |
| 466 |
|
_Result (__fastcall *)(_Arg1, _Arg2)>(_Left)); |
| 467 |
|
} |
| 468 |
|
#endif /* _M_CEE */ |
| 469 |
|
#endif /* _M_IX86 */ |
| 470 |
|
|
| 471 |
|
#ifdef _M_CEE |
| 472 |
|
template<class _Arg1, |
| 473 |
|
class _Arg2, |
| 474 |
|
class _Result> inline |
| 475 |
|
pointer_to_binary_function<_Arg1, _Arg2, _Result, |
| 476 |
|
_Result(__clrcall *)(_Arg1, _Arg2)> |
| 477 |
|
ptr_fun(_Result (__clrcall *_Left)(_Arg1, _Arg2)) |
| 478 |
|
{ // return pointer_to_binary_function functor adapter |
| 479 |
|
return (std::pointer_to_binary_function<_Arg1, _Arg2, _Result, |
| 480 |
|
_Result (__clrcall *)(_Arg1, _Arg2)>(_Left)); |
| 481 |
|
} |
| 482 |
|
#endif /* _M_CEE */ |
| 483 |
|
|
| 484 |
|
// TEMPLATE CLASS mem_fun_t |
| 485 |
|
template<class _Result, |
| 486 |
|
class _Ty> |
| 487 |
|
class mem_fun_t |
| 488 |
|
: public unary_function<_Ty *, _Result> |
| 489 |
|
{ // functor adapter (*p->*pfunc)(), non-const *pfunc |
| 490 |
|
public: |
| 491 |
|
explicit mem_fun_t(_Result (_Ty::*_Pm)()) |
| 492 |
|
: _Pmemfun(_Pm) |
| 493 |
|
{ // construct from pointer |
| 494 |
|
} |
| 495 |
|
|
| 496 |
|
_Result operator()(_Ty *_Pleft) const |
| 497 |
|
{ // call function |
| 498 |
|
return ((_Pleft->*_Pmemfun)()); |
| 499 |
|
} |
| 500 |
|
|
| 501 |
|
private: |
| 502 |
|
_Result (_Ty::*_Pmemfun)(); // the member function pointer |
| 503 |
|
}; |
| 504 |
|
|
| 505 |
|
// TEMPLATE CLASS mem_fun1_t |
| 506 |
|
template<class _Result, |
| 507 |
|
class _Ty, |
| 508 |
|
class _Arg> |
| 509 |
|
class mem_fun1_t |
| 510 |
|
: public binary_function<_Ty *, _Arg, _Result> |
| 511 |
|
{ // functor adapter (*p->*pfunc)(val), non-const *pfunc |
| 512 |
|
public: |
| 513 |
|
explicit mem_fun1_t(_Result (_Ty::*_Pm)(_Arg)) |
| 514 |
|
: _Pmemfun(_Pm) |
| 515 |
|
{ // construct from pointer |
| 516 |
|
} |
| 517 |
|
|
| 518 |
|
_Result operator()(_Ty *_Pleft, _Arg _Right) const |
| 519 |
|
{ // call function with operand |
| 520 |
|
return ((_Pleft->*_Pmemfun)(_Right)); |
| 521 |
|
} |
| 522 |
|
|
| 523 |
|
private: |
| 524 |
|
_Result (_Ty::*_Pmemfun)(_Arg); // the member function pointer |
| 525 |
|
}; |
| 526 |
|
|
| 527 |
|
// TEMPLATE CLASS const_mem_fun_t |
| 528 |
|
template<class _Result, |
| 529 |
|
class _Ty> |
| 530 |
|
class const_mem_fun_t |
| 531 |
|
: public unary_function<const _Ty *, _Result> |
| 532 |
|
{ // functor adapter (*p->*pfunc)(), const *pfunc |
| 533 |
|
public: |
| 534 |
|
explicit const_mem_fun_t(_Result (_Ty::*_Pm)() const) |
| 535 |
|
: _Pmemfun(_Pm) |
| 536 |
|
{ // construct from pointer |
| 537 |
|
} |
| 538 |
|
|
| 539 |
|
_Result operator()(const _Ty *_Pleft) const |
| 540 |
|
{ // call function |
| 541 |
|
return ((_Pleft->*_Pmemfun)()); |
| 542 |
|
} |
| 543 |
|
|
| 544 |
|
private: |
| 545 |
|
_Result (_Ty::*_Pmemfun)() const; // the member function pointer |
| 546 |
|
}; |
| 547 |
|
|
| 548 |
|
// TEMPLATE CLASS const_mem_fun1_t |
| 549 |
|
template<class _Result, |
| 550 |
|
class _Ty, |
| 551 |
|
class _Arg> |
| 552 |
|
class const_mem_fun1_t |
| 553 |
|
: public binary_function<const _Ty *, _Arg, _Result> |
| 554 |
|
{ // functor adapter (*p->*pfunc)(val), const *pfunc |
| 555 |
|
public: |
| 556 |
|
explicit const_mem_fun1_t(_Result (_Ty::*_Pm)(_Arg) const) |
| 557 |
|
: _Pmemfun(_Pm) |
| 558 |
|
{ // construct from pointer |
| 559 |
|
} |
| 560 |
|
|
| 561 |
|
_Result operator()(const _Ty *_Pleft, _Arg _Right) const |
| 562 |
|
{ // call function with operand |
| 563 |
|
return ((_Pleft->*_Pmemfun)(_Right)); |
| 564 |
|
} |
| 565 |
|
|
| 566 |
|
private: |
| 567 |
|
_Result (_Ty::*_Pmemfun)(_Arg) const; // the member function pointer |
| 568 |
|
}; |
| 569 |
|
|
| 570 |
|
// TEMPLATE FUNCTION mem_fun |
| 571 |
|
template<class _Result, |
| 572 |
|
class _Ty> inline |
| 573 |
|
mem_fun_t<_Result, _Ty> mem_fun(_Result (_Ty::*_Pm)()) |
| 574 |
|
{ // return a mem_fun_t functor adapter |
| 575 |
|
return (std::mem_fun_t<_Result, _Ty>(_Pm)); |
| 576 |
|
} |
| 577 |
|
|
| 578 |
|
template<class _Result, |
| 579 |
|
class _Ty, |
| 580 |
|
class _Arg> inline |
| 581 |
|
mem_fun1_t<_Result, _Ty, _Arg> mem_fun(_Result (_Ty::*_Pm)(_Arg)) |
| 582 |
|
{ // return a mem_fun1_t functor adapter |
| 583 |
|
return (std::mem_fun1_t<_Result, _Ty, _Arg>(_Pm)); |
| 584 |
|
} |
| 585 |
|
|
| 586 |
|
template<class _Result, |
| 587 |
|
class _Ty> inline |
| 588 |
|
const_mem_fun_t<_Result, _Ty> |
| 589 |
|
mem_fun(_Result (_Ty::*_Pm)() const) |
| 590 |
|
{ // return a const_mem_fun_t functor adapter |
| 591 |
|
return (std::const_mem_fun_t<_Result, _Ty>(_Pm)); |
| 592 |
|
} |
| 593 |
|
|
| 594 |
|
template<class _Result, |
| 595 |
|
class _Ty, |
| 596 |
|
class _Arg> inline |
| 597 |
|
const_mem_fun1_t<_Result, _Ty, _Arg> |
| 598 |
|
mem_fun(_Result (_Ty::*_Pm)(_Arg) const) |
| 599 |
|
{ // return a const_mem_fun1_t functor adapter |
| 600 |
|
return (std::const_mem_fun1_t<_Result, _Ty, _Arg>(_Pm)); |
| 601 |
|
} |
| 602 |
|
|
| 603 |
|
// TEMPLATE FUNCTION mem_fun1 (retained) |
| 604 |
|
template<class _Result, |
| 605 |
|
class _Ty, |
| 606 |
|
class _Arg> inline |
| 607 |
|
mem_fun1_t<_Result, _Ty, _Arg> mem_fun1(_Result (_Ty::*_Pm)(_Arg)) |
| 608 |
|
{ // return a mem_fun1_t functor adapter |
| 609 |
|
return (std::mem_fun1_t<_Result, _Ty, _Arg>(_Pm)); |
| 610 |
|
} |
| 611 |
|
|
| 612 |
|
// TEMPLATE CLASS mem_fun_ref_t |
| 613 |
|
template<class _Result, |
| 614 |
|
class _Ty> |
| 615 |
|
class mem_fun_ref_t |
| 616 |
|
: public unary_function<_Ty, _Result> |
| 617 |
|
{ // functor adapter (*left.*pfunc)(), non-const *pfunc |
| 618 |
|
public: |
| 619 |
|
explicit mem_fun_ref_t(_Result (_Ty::*_Pm)()) |
| 620 |
|
: _Pmemfun(_Pm) |
| 621 |
|
{ // construct from pointer |
| 622 |
|
} |
| 623 |
|
|
| 624 |
|
_Result operator()(_Ty& _Left) const |
| 625 |
|
{ // call function |
| 626 |
|
return ((_Left.*_Pmemfun)()); |
| 627 |
|
} |
| 628 |
|
|
| 629 |
|
private: |
| 630 |
|
_Result (_Ty::*_Pmemfun)(); // the member function pointer |
| 631 |
|
}; |
| 632 |
|
|
| 633 |
|
// TEMPLATE CLASS mem_fun1_ref_t |
| 634 |
|
template<class _Result, |
| 635 |
|
class _Ty, |
| 636 |
|
class _Arg> |
| 637 |
|
class mem_fun1_ref_t |
| 638 |
|
: public binary_function<_Ty, _Arg, _Result> |
| 639 |
|
{ // functor adapter (*left.*pfunc)(val), non-const *pfunc |
| 640 |
|
public: |
| 641 |
|
explicit mem_fun1_ref_t(_Result (_Ty::*_Pm)(_Arg)) |
| 642 |
|
: _Pmemfun(_Pm) |
| 643 |
|
{ // construct from pointer |
| 644 |
|
} |
| 645 |
|
|
| 646 |
|
_Result operator()(_Ty& _Left, _Arg _Right) const |
| 647 |
|
{ // call function with operand |
| 648 |
|
return ((_Left.*_Pmemfun)(_Right)); |
| 649 |
|
} |
| 650 |
|
|
| 651 |
|
private: |
| 652 |
|
_Result (_Ty::*_Pmemfun)(_Arg); // the member function pointer |
| 653 |
|
}; |
| 654 |
|
|
| 655 |
|
// TEMPLATE CLASS const_mem_fun_ref_t |
| 656 |
|
template<class _Result, |
| 657 |
|
class _Ty> |
| 658 |
|
class const_mem_fun_ref_t |
| 659 |
|
: public unary_function<_Ty, _Result> |
| 660 |
|
{ // functor adapter (*left.*pfunc)(), const *pfunc |
| 661 |
|
public: |
| 662 |
|
explicit const_mem_fun_ref_t(_Result (_Ty::*_Pm)() const) |
| 663 |
|
: _Pmemfun(_Pm) |
| 664 |
|
{ // construct from pointer |
| 665 |
|
} |
| 666 |
|
|
| 667 |
|
_Result operator()(const _Ty& _Left) const |
| 668 |
|
{ // call function |
| 669 |
|
return ((_Left.*_Pmemfun)()); |
| 670 |
|
} |
| 671 |
|
|
| 672 |
|
private: |
| 673 |
|
_Result (_Ty::*_Pmemfun)() const; // the member function pointer |
| 674 |
|
}; |
| 675 |
|
|
| 676 |
|
// TEMPLATE CLASS const_mem_fun1_ref_t |
| 677 |
|
template<class _Result, |
| 678 |
|
class _Ty, |
| 679 |
|
class _Arg> |
| 680 |
|
class const_mem_fun1_ref_t |
| 681 |
|
: public binary_function<_Ty, _Arg, _Result> |
| 682 |
|
{ // functor adapter (*left.*pfunc)(val), const *pfunc |
| 683 |
|
public: |
| 684 |
|
explicit const_mem_fun1_ref_t(_Result (_Ty::*_Pm)(_Arg) const) |
| 685 |
|
: _Pmemfun(_Pm) |
| 686 |
|
{ // construct from pointer |
| 687 |
|
} |
| 688 |
|
|
| 689 |
|
_Result operator()(const _Ty& _Left, _Arg _Right) const |
| 690 |
|
{ // call function with operand |
| 691 |
|
return ((_Left.*_Pmemfun)(_Right)); |
| 692 |
|
} |
| 693 |
|
|
| 694 |
|
private: |
| 695 |
|
_Result (_Ty::*_Pmemfun)(_Arg) const; // the member function pointer |
| 696 |
|
}; |
| 697 |
|
|
| 698 |
|
// TEMPLATE FUNCTION mem_fun_ref |
| 699 |
|
template<class _Result, |
| 700 |
|
class _Ty> inline |
| 701 |
|
mem_fun_ref_t<_Result, _Ty> mem_fun_ref(_Result (_Ty::*_Pm)()) |
| 702 |
|
{ // return a mem_fun_ref_t functor adapter |
| 703 |
|
return (std::mem_fun_ref_t<_Result, _Ty>(_Pm)); |
| 704 |
|
} |
| 705 |
|
|
| 706 |
|
template<class _Result, |
| 707 |
|
class _Ty, |
| 708 |
|
class _Arg> inline |
| 709 |
|
mem_fun1_ref_t<_Result, _Ty, _Arg> |
| 710 |
|
mem_fun_ref(_Result (_Ty::*_Pm)(_Arg)) |
| 711 |
|
{ // return a mem_fun1_ref_t functor adapter |
| 712 |
|
return (std::mem_fun1_ref_t<_Result, _Ty, _Arg>(_Pm)); |
| 713 |
|
} |
| 714 |
|
|
| 715 |
|
template<class _Result, |
| 716 |
|
class _Ty> inline |
| 717 |
|
const_mem_fun_ref_t<_Result, _Ty> |
| 718 |
|
mem_fun_ref(_Result (_Ty::*_Pm)() const) |
| 719 |
|
{ // return a const_mem_fun_ref_t functor adapter |
| 720 |
|
return (std::const_mem_fun_ref_t<_Result, _Ty>(_Pm)); |
| 721 |
|
} |
| 722 |
|
|
| 723 |
|
template<class _Result, |
| 724 |
|
class _Ty, |
| 725 |
|
class _Arg> inline |
| 726 |
|
const_mem_fun1_ref_t<_Result, _Ty, _Arg> |
| 727 |
|
mem_fun_ref(_Result (_Ty::*_Pm)(_Arg) const) |
| 728 |
|
{ // return a const_mem_fun1_ref_t functor adapter |
| 729 |
|
return (std::const_mem_fun1_ref_t<_Result, _Ty, _Arg>(_Pm)); |
| 730 |
|
} |
| 731 |
|
|
| 732 |
|
// TEMPLATE FUNCTION mem_fun1_ref (retained) |
| 733 |
|
template<class _Result, |
| 734 |
|
class _Ty, |
| 735 |
|
class _Arg> inline |
| 736 |
|
mem_fun1_ref_t<_Result, _Ty, _Arg> mem_fun1_ref(_Result (_Ty::*_Pm)(_Arg)) |
| 737 |
|
{ // return a mem_fun1_ref_t functor adapter |
| 738 |
|
return (std::mem_fun1_ref_t<_Result, _Ty, _Arg>(_Pm)); |
| 739 |
|
} |
| 740 |
|
|
| 741 |
|
#if _HAS_TRADITIONAL_STL |
| 742 |
|
// TEMPLATE STRUCT identity |
| 743 |
|
template<class _Arg> |
| 744 |
|
struct identity |
| 745 |
|
: public unary_function<_Arg, _Arg> |
| 746 |
|
{ // functor for unary identity operator |
| 747 |
|
_Arg operator()(const _Arg& _Left) const |
| 748 |
|
{ // apply identity operator to operand |
| 749 |
|
return (_Left); |
| 750 |
|
} |
| 751 |
|
}; |
| 752 |
|
|
| 753 |
|
// TEMPLATE STRUCT project1st |
| 754 |
|
template<class _Arg1, |
| 755 |
|
class _Arg2> |
| 756 |
|
struct project1st |
| 757 |
|
: public binary_function<_Arg1, _Arg2, _Arg1> |
| 758 |
|
{ // functor for binary first of two arg selector operator |
| 759 |
|
_Arg1 operator()(const _Arg1& _Left, const _Arg2&) const |
| 760 |
|
{ // apply first selector operator to two operands |
| 761 |
|
return (_Left); |
| 762 |
|
} |
| 763 |
|
}; |
| 764 |
|
|
| 765 |
|
// TEMPLATE STRUCT project2nd |
| 766 |
|
template<class _Arg1, |
| 767 |
|
class _Arg2> |
| 768 |
|
struct project2nd |
| 769 |
|
: public binary_function<_Arg1, _Arg2, _Arg2> |
| 770 |
|
{ // functor for binary second of two arg selector operator |
| 771 |
|
_Arg2 operator()(const _Arg1&, const _Arg2& _Right) const |
| 772 |
|
{ // apply second selector operator to two operands |
| 773 |
|
return (_Right); |
| 774 |
|
} |
| 775 |
|
}; |
| 776 |
|
|
| 777 |
|
// TEMPLATE STRUCT select1st |
| 778 |
|
template<class _Pair> |
| 779 |
|
struct select1st |
| 780 |
|
: public unary_function<_Pair, typename _Pair::first_type> |
| 781 |
|
{ // functor for unary first of pair selector operator |
| 782 |
|
const typename _Pair::first_type& operator()(const _Pair& _Left) const |
| 783 |
|
{ // apply first selector operator to pair operand |
| 784 |
|
return (_Left.first); |
| 785 |
|
} |
| 786 |
|
}; |
| 787 |
|
|
| 788 |
|
// TEMPLATE STRUCT select2nd |
| 789 |
|
template<class _Pair> |
| 790 |
|
struct select2nd |
| 791 |
|
: public unary_function<_Pair, typename _Pair::second_type> |
| 792 |
|
{ // functor for unary second of pair selector operator |
| 793 |
|
const typename _Pair::second_type& operator()(const _Pair& _Left) const |
| 794 |
|
{ // apply second selector operator to pair operand |
| 795 |
|
return (_Left.second); |
| 796 |
|
} |
| 797 |
|
}; |
| 798 |
|
|
| 799 |
|
// TEMPLATE CLASS unary_compose |
| 800 |
|
template<class _Fn1, |
| 801 |
|
class _Fn2> |
| 802 |
|
class unary_compose |
| 803 |
|
: public unary_function<typename _Fn2::argument_type, |
| 804 |
|
typename _Fn1::result_type> |
| 805 |
|
{ // functor for f1(f2(x)) |
| 806 |
|
public: |
| 807 |
|
unary_compose(const _Fn1& _Func1, const _Fn2& _Func2) |
| 808 |
|
: _Functor1(_Func1), _Functor2(_Func2) |
| 809 |
|
{ // construct from functors |
| 810 |
|
} |
| 811 |
|
|
| 812 |
|
typename _Fn1::result_type operator()( |
| 813 |
|
const typename _Fn2::argument_type& _Left) const |
| 814 |
|
{ // apply functors to operand |
| 815 |
|
return (_Functor1(_Functor2(_Left))); |
| 816 |
|
} |
| 817 |
|
|
| 818 |
|
protected: |
| 819 |
|
_Fn1 _Functor1; |
| 820 |
|
_Fn2 _Functor2; |
| 821 |
|
}; |
| 822 |
|
|
| 823 |
|
// TEMPLATE FUNCTION compose1 |
| 824 |
|
template<class _Fn1, |
| 825 |
|
class _Fn2> inline |
| 826 |
|
unary_compose<_Fn1, _Fn2> compose1(const _Fn1& _Func1, |
| 827 |
|
const _Fn2& _Func2) |
| 828 |
|
{ // return a unary_compose<_Fn1, _Fn2> functor adapter |
| 829 |
|
return (unary_compose<_Fn1, _Fn2>(_Func1, _Func2)); |
| 830 |
|
} |
| 831 |
|
|
| 832 |
|
// TEMPLATE CLASS binary_compose |
| 833 |
|
template<class _Fn1, |
| 834 |
|
class _Fn2, |
| 835 |
|
class _Fn3> |
| 836 |
|
class binary_compose |
| 837 |
|
: public unary_function<typename _Fn2::argument_type, |
| 838 |
|
typename _Fn1::result_type> |
| 839 |
|
{ // functor for f1(f2(x), f3(x)) |
| 840 |
|
public: |
| 841 |
|
binary_compose(const _Fn1& _Func1, const _Fn2& _Func2, const _Fn3& _Func3) |
| 842 |
|
: _Functor1(_Func1), _Functor2(_Func2), _Functor3(_Func3) |
| 843 |
|
{ // construct from functors |
| 844 |
|
} |
| 845 |
|
|
| 846 |
|
typename _Fn1::result_type operator()( |
| 847 |
|
const typename _Fn2::argument_type& _Left) const |
| 848 |
|
{ // apply functors to operand |
| 849 |
|
return (_Functor1(_Functor2(_Left), _Functor3(_Left))); |
| 850 |
|
} |
| 851 |
|
|
| 852 |
|
protected: |
| 853 |
|
_Fn1 _Functor1; |
| 854 |
|
_Fn2 _Functor2; |
| 855 |
|
_Fn3 _Functor3; |
| 856 |
|
}; |
| 857 |
|
|
| 858 |
|
// TEMPLATE FUNCTION compose2 |
| 859 |
|
template<class _Fn1, |
| 860 |
|
class _Fn2, |
| 861 |
|
class _Fn3> inline |
| 862 |
|
binary_compose<_Fn1, _Fn2, _Fn3> compose2(const _Fn1& _Func1, |
| 863 |
|
const _Fn2& _Func2, const _Fn3& _Func3) |
| 864 |
|
{ // return a binary_compose<_Fn1, _Fn2, _Fn3> functor adapter |
| 865 |
|
return (binary_compose<_Fn1, _Fn2, _Fn3>(_Func1, _Func2, _Func3)); |
| 866 |
|
} |
| 867 |
|
#endif /* _HAS_TRADITIONAL_STL */ |
| 868 |
|
|
| 869 |
|
_STD_END |
| 870 |
|
|
| 871 |
|
#if _HAS_TR1 |
| 872 |
|
#include <exception> |
| 873 |
|
#include <typeinfo> |
| 874 |
|
#include <xrefwrap> |
| 875 |
|
|
| 876 |
|
#ifndef _XSTD2 |
| 877 |
|
#define _XSTD2 |
| 878 |
|
#endif /* _XSTD2 */ |
| 879 |
|
|
| 880 |
|
_STD_BEGIN |
| 881 |
|
namespace tr1 { // TR1 additions |
| 882 |
|
|
| 883 |
|
// IMPLEMENT std::tr1::mem_fn |
| 884 |
|
// TEMPLATE FUNCTION mem_fn |
| 885 |
|
template<class _Rx, |
| 886 |
|
class _Arg0> |
| 887 |
|
_Call_wrapper<_Callable_pmd<_Rx _Arg0::*const, _Arg0> > |
| 888 |
|
mem_fn(_Rx _Arg0::*const _Pmd) |
| 889 |
|
{ // return data object wrapper |
| 890 |
|
return (_Call_wrapper<_Callable_pmd<_Rx _Arg0::*const, _Arg0> >(_Pmd)); |
| 891 |
|
} |
| 892 |
|
|
| 893 |
|
// define multiple-argument variants of mem_fn |
| 894 |
|
#define _INCL_FILE <xxmem_fn> |
| 895 |
|
#define _NOZERO |
| 896 |
|
#include <xfwrap> |
| 897 |
|
|
| 898 |
|
// IMPLEMENT std::tr1::function |
| 899 |
|
// HELPERS |
| 900 |
|
|
| 901 |
|
#if _NO_SFINAE |
| 902 |
|
#define _NOT_INTEGRAL(ty) |
| 903 |
|
typedef int _Unutterable; |
| 904 |
|
|
| 905 |
|
#else /* _NO_SFINAE */ |
| 906 |
|
template<bool, |
| 907 |
|
class _Ty> |
| 908 |
|
struct _Not_integral; |
| 909 |
|
|
| 910 |
|
template<class _Ty> |
| 911 |
|
struct _Not_integral<true, _Ty> |
| 912 |
|
{ // distinguish non-integral types |
| 913 |
|
typedef _Ty _Type; |
| 914 |
|
}; |
| 915 |
|
|
| 916 |
|
#define _NOT_INTEGRAL(ty) , \ |
| 917 |
|
typename _Not_integral<!_Is_integral<ty>::value, int>::_Type = 0 |
| 918 |
|
|
| 919 |
|
typedef struct _Unnamed *_Unutterable; |
| 920 |
|
#endif /* _NO_SFINAE */ |
| 921 |
|
|
| 922 |
|
// CLASS bad_function_call |
| 923 |
|
class bad_function_call |
| 924 |
|
: public _XSTD exception |
| 925 |
|
{ // null function pointer exception |
| 926 |
|
public: |
| 927 |
|
explicit bad_function_call(const char * = 0) |
| 928 |
|
{ // construct with ignored message |
| 929 |
|
} |
| 930 |
|
|
| 931 |
|
virtual const char *__CLR_OR_THIS_CALL what() const _THROW0() |
| 932 |
|
{ // return pointer to message string |
| 933 |
|
return ("bad function call"); |
| 934 |
|
} |
| 935 |
|
}; |
| 936 |
|
|
| 937 |
|
_CRTIMP2_PURE __declspec(noreturn) void __CLRCALL_PURE_OR_CDECL _Xfunc(); |
| 938 |
|
|
| 939 |
|
// TEMPLATE FUNCTION _Get_function_impl |
| 940 |
|
template<class _Tx> |
| 941 |
|
struct _Get_function_impl; |
| 942 |
|
|
| 943 |
|
// function implementation: |
| 944 |
|
#define _INCL_FILE <xxfunction> |
| 945 |
|
#include <xfwrap> |
| 946 |
|
|
| 947 |
|
// TEMPLATE CLASS function |
| 948 |
|
template<class _Fty> |
| 949 |
|
class function |
| 950 |
|
: public _Get_function_impl<_Fty>::_Type |
| 951 |
|
{ // wrapper for callable objects |