root/core/functional.hpp

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. Op
  2. arg1
  3. arg1
  4. Op
  5. arg2
  6. arg2
  7. Op
  8. arg3
  9. arg3
  10. Op
  11. arg4
  12. arg4
  13. Op

   1 #ifndef libjmmcg_core_functional_hpp
   2 #define libjmmcg_core_functional_hpp
   3 
   4 // TITLE:
   5 //
   6 // VERSION:
   7 // MS Source Safe: $Header: svn+ssh://jmmcg@svn.code.sf.net/p/libjmmcg/code/trunk/libjmmcg/core/functional.hpp 2055 2017-05-13 19:35:47Z jmmcg $
   8 // CVS: $Id: functional.hpp,v 1.14 2008-08-09 17:44:48 jmmcg Exp $
   9 //
  10 // AUTHOR:
  11 // Created by J.M.McGuiness, E-mail: coder@hussar.me.uk
  12 //
  13 // DESCRIPTION:
  14 // If these adaptor classes look similar to the STL variants, you'd be right.
  15 // They are. But I need adaptors for functions with more than just 1 argument.
  16 //
  17 // VERSION HISTORY:
  18 // 3/3/2004 Creation of version 1.0
  19 //
  20 // LEGALITIES:
  21 // Copyright © 2004 by J.M.McGuiness, all rights reserved.
  22 //
  23 // This library is free software; you can redistribute it and/or
  24 // modify it under the terms of the GNU Lesser General Public
  25 // License as published by the Free Software Foundation; either
  26 // version 2.1 of the License, or (at your option) any later version.
  27 //
  28 // This library is distributed in the hope that it will be useful,
  29 // but WITHOUT ANY WARRANTY; without even the implied warranty of
  30 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  31 // Lesser General Public License for more details.
  32 //
  33 // You should have received a copy of the GNU Lesser General Public
  34 // License along with this library; if not, write to the Free Software
  35 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  36 //
  37 /////////////////////////////////////////////////////////////////////////////
  38 
  39 #include"non_copyable.hpp"
  40 
  41 #include<cassert>
  42 
  43 namespace jmmcg {
  44 
  45 /*
  46 
  47   Member function functors.
  48 
  49 */
  50 
  51         template<typename RetType,typename ObjType>
  52         class const_mem_fun_ref_t {
  53         public:
  54                 typedef typename ObjType object_type;
  55                 typedef typename RetType result_type;
  56                 typedef RetType (__fastcall ObjType::*fun_type)(void) const;
  57 
  58                 explicit __stdcall const_mem_fun_ref_t(const fun_type p) noexcept(true)
  59                 : pmf(p) {
  60                         assert(pmf);
  61                 }
  62                 __stdcall const_mem_fun_ref_t(const const_mem_fun_ref_t &p) noexcept(true)
  63                 : pmf(p.pmf) {
  64                         assert(pmf);
  65                 }
  66                 __stdcall ~const_mem_fun_ref_t(void) noexcept(true) {
  67                 }
  68 
  69                 RetType __fastcall operator()(const ObjType &p) const {
  70                         return (p.*pmf)();
  71                 }
  72                 RetType __fastcall operator()(ObjType &p) const {
  73                         return (p.*pmf)();
  74                 }
  75 
  76         private:
  77                 const fun_type pmf;
  78         };
  79 
  80         template<typename RetType,typename ObjType,typename Arg1>
  81         class const_mem_fun1_ref_t {
  82         public:
  83                 typedef typename ObjType object_type;
  84                 typedef typename RetType result_type;
  85                 typedef typename Arg1 first_argument_type;
  86                 typedef RetType (__fastcall ObjType::*fun_type)(const Arg1 &) const;
  87 
  88                 explicit __stdcall const_mem_fun1_ref_t(const fun_type p) noexcept(true)
  89                 : pmf(p) {
  90                         assert(pmf);
  91                 }
  92                 __stdcall const_mem_fun1_ref_t(const const_mem_fun1_ref_t &p) noexcept(true)
  93                 : pmf(p.pmf) {
  94                         assert(pmf);
  95                 }
  96                 __stdcall ~const_mem_fun1_ref_t(void) noexcept(true) {
  97                 }
  98 
  99                 RetType __fastcall operator()(const ObjType &p,const Arg1 &b) const {
 100                         return (p.*pmf)(b);
 101                 }
 102                 RetType __fastcall operator()(ObjType &p,const Arg1 &b) const {
 103                         return (p.*pmf)(b);
 104                 }
 105 
 106         private:
 107                 const fun_type pmf;
 108         };
 109 
 110         template<typename RetType,typename ObjType,typename Arg1,typename Arg2>
 111         class const_mem_fun2_ref_t {
 112         public:
 113                 typedef typename ObjType object_type;
 114                 typedef typename RetType result_type;
 115                 typedef typename Arg1 first_argument_type;
 116                 typedef typename Arg2 second_argument_type;
 117                 typedef RetType (__fastcall ObjType::*fun_type)(const Arg1 &,const Arg2 &) const;
 118 
 119                 explicit __stdcall const_mem_fun2_ref_t(const fun_type p) noexcept(true)
 120                 : pmf(p) {
 121                         assert(pmf);
 122                 }
 123                 __stdcall const_mem_fun2_ref_t(const const_mem_fun2_ref_t &p) noexcept(true)
 124                 : pmf(p.pmf) {
 125                         assert(pmf);
 126                 }
 127                 __stdcall ~const_mem_fun2_ref_t(void) noexcept(true) {
 128                 }
 129 
 130                 RetType __fastcall operator()(const ObjType &p,const Arg1 &b,const Arg2 &c) const {
 131                         return (p.*pmf)(b,c);
 132                 }
 133                 RetType __fastcall operator()(ObjType &p,const Arg1 &b,const Arg2 &c) const {
 134                         return (p.*pmf)(b,c);
 135                 }
 136 
 137         private:
 138                 const fun_type pmf;
 139         };
 140 
 141         template<typename RetType,typename ObjType>
 142         class mem_fun_ref_t {
 143         public:
 144                 typedef typename ObjType object_type;
 145                 typedef typename RetType result_type;
 146                 typedef RetType (__fastcall ObjType::*fun_type)(void);
 147 
 148                 explicit __stdcall mem_fun_ref_t(const fun_type p) noexcept(true)
 149                 : pmf(p) {
 150                         assert(pmf);
 151                 }
 152                 __stdcall mem_fun_ref_t(const mem_fun_ref_t &p) noexcept(true)
 153                 : pmf(p.pmf) {
 154                         assert(pmf);
 155                 }
 156                 __stdcall ~mem_fun_ref_t(void) noexcept(true) {
 157                 }
 158 
 159                 RetType __fastcall operator()(void) const {
 160                         return (obj.*pmf)();
 161                 }
 162                 RetType __fastcall operator()(void) {
 163                         return (obj.*pmf)();
 164                 }
 165 
 166         private:
 167                 const fun_type pmf;
 168                 ObjType obj;
 169         };
 170 
 171         template<typename RetType,typename ObjType,typename Arg1>
 172         class mem_fun1_ref_t {
 173         public:
 174                 typedef typename ObjType object_type;
 175                 typedef typename RetType result_type;
 176                 typedef typename Arg1 first_argument_type;
 177                 typedef RetType (__fastcall ObjType::*fun_type)(const Arg1 &);
 178 
 179                 explicit __stdcall mem_fun1_ref_t(const fun_type p) noexcept(true)
 180                 : pmf(p) {
 181                         assert(pmf);
 182                 }
 183                 __stdcall mem_fun1_ref_t(const mem_fun1_ref_t &p) noexcept(true)
 184                 : pmf(p.pmf) {
 185                         assert(pmf);
 186                 }
 187                 __stdcall ~mem_fun1_ref_t(void) noexcept(true) {
 188                 }
 189 
 190                 RetType __fastcall operator()(const Arg1 &a) const {
 191                         return (obj.*pmf)(a);
 192                 }
 193                 RetType __fastcall operator()(const Arg1 &a) {
 194                         return (obj.*pmf)(a);
 195                 }
 196 
 197         private:
 198                 const fun_type pmf;
 199                 ObjType obj;
 200         };
 201 /* TODO JMG: not apparently needed....?
 202         template<typename RetType,typename ObjType,typename Arg1,typename Arg2>
 203         class mem_fun2_ref_t {
 204         public:
 205                 typedef typename ObjType object_type;
 206                 typedef typename RetType result_type;
 207                 typedef typename Arg1 first_argument_type;
 208                 typedef typename Arg2 second_argument_type;
 209                 typedef RetType (__fastcall ObjType::*fun_type)(const Arg1 &,const Arg2 &);
 210 
 211                 explicit __stdcall mem_fun2_ref_t(const fun_type p) noexcept(true)
 212                 : pmf(p) {
 213                         assert(pmf);
 214                 }
 215                 __stdcall mem_fun2_ref_t(const mem_fun2_ref_t &p) noexcept(true)
 216                 : pmf(p.pmf) {
 217                         assert(pmf);
 218                 }
 219                 __stdcall ~mem_fun2_ref_t(void) noexcept(true) {
 220                 }
 221                 void operator=(const mem_fun2_ref_t &)=delete;
 222 
 223                 RetType __fastcall operator()(const Arg1 &a,const Arg2 &b) const {
 224                         return (obj.*pmf)(a,b);
 225                 }
 226                 RetType __fastcall operator()(const Arg1 &a,const Arg2 &b) {
 227                         return (obj.*pmf)(a,b);
 228                 }
 229 
 230         private:
 231                 const fun_type pmf;
 232                 ObjType obj;
 233         };
 234 
 235         template<typename RetType,typename ObjType,typename Arg1,typename Arg2,typename Arg3>
 236         class mem_fun3_ref_t {
 237         public:
 238                 typedef typename ObjType object_type;
 239                 typedef typename RetType result_type;
 240                 typedef typename Arg1 first_argument_type;
 241                 typedef typename Arg2 second_argument_type;
 242                 typedef typename Arg3 third_argument_type;
 243                 typedef RetType (__fastcall ObjType::*fun_type)(const Arg1 &,const Arg2 &,const Arg3 &);
 244 
 245                 explicit __stdcall mem_fun3_ref_t(const fun_type p) noexcept(true)
 246                 : pmf(p) {
 247                         assert(pmf);
 248                 }
 249                 __stdcall mem_fun3_ref_t(const mem_fun3_ref_t &p) noexcept(true)
 250                 : pmf(p.pmf) {
 251                         assert(pmf);
 252                 }
 253                 __stdcall ~mem_fun3_ref_t(void) noexcept(true) {
 254                 }
 255                 void operator=(const mem_fun3_ref_t &)=delete;
 256 
 257                 RetType __fastcall operator()(const Arg1 &a,const Arg2 &b,const Arg3 &c) const {
 258                         return (obj.*pmf)(a,b,c);
 259                 }
 260                 RetType __fastcall operator()(const Arg1 &a,const Arg2 &b,const Arg3 &c) {
 261                         return (obj.*pmf)(a,b,c);
 262                 }
 263 
 264         private:
 265                 const fun_type pmf;
 266                 ObjType obj;
 267         };
 268 
 269         template<typename RetType,typename ObjType,typename Arg1,typename Arg2,typename Arg3,typename Arg4>
 270         class mem_fun4_ref_t {
 271         public:
 272                 typedef typename ObjType object_type;
 273                 typedef typename RetType result_type;
 274                 typedef typename Arg1 first_argument_type;
 275                 typedef typename Arg2 second_argument_type;
 276                 typedef typename Arg3 third_argument_type;
 277                 typedef typename Arg4 fourth_argument_type;
 278                 typedef RetType (__fastcall ObjType::*fun_type)(const Arg1 &,const Arg2 &,const Arg3 &,const Arg4 &);
 279 
 280                 explicit __stdcall mem_fun4_ref_t(const fun_type p) noexcept(true)
 281                 : pmf(p) {
 282                         assert(pmf);
 283                 }
 284                 __stdcall mem_fun4_ref_t(const mem_fun4_ref_t &p) noexcept(true)
 285                 : pmf(p.pmf) {
 286                         assert(pmf);
 287                 }
 288                 __stdcall ~mem_fun4_ref_t(void) noexcept(true) {
 289                 }
 290 
 291                 RetType __fastcall operator()(const Arg1 &a,const Arg2 &b,const Arg3 &c,const Arg4 &d) const {
 292                         return (obj.*pmf)(a,b,c,d);
 293                 }
 294                 RetType __fastcall operator()(const Arg1 &a,const Arg2 &b,const Arg3 &c,const Arg4 &d) {
 295                         return (obj.*pmf)(a,b,c,d);
 296                 }
 297 
 298         private:
 299                 const fun_type pmf;
 300                 ObjType obj;
 301         };
 302 */
 303         template<typename RetType,typename ObjType>
 304         class copy_mem_fun_ref_t {
 305         public:
 306                 typedef typename ObjType object_type;
 307                 typedef typename RetType result_type;
 308                 typedef RetType (__fastcall ObjType::*fun_type)(void);
 309 
 310                 explicit __stdcall copy_mem_fun_ref_t(const fun_type p) noexcept(true)
 311                 : pmf(p) {
 312                         assert(pmf);
 313                 }
 314                 __stdcall copy_mem_fun_ref_t(const copy_mem_fun_ref_t &p) noexcept(true)
 315                 : pmf(p.pmf) {
 316                         assert(pmf);
 317                 }
 318                 __stdcall ~copy_mem_fun_ref_t(void) noexcept(true) {
 319                 }
 320 
 321                 RetType __fastcall operator()(const ObjType &p) const {
 322                         return (ObjType(p).*pmf)();
 323                 }
 324                 RetType __fastcall operator()(ObjType &p) const {
 325                         return (ObjType(p).*pmf)();
 326                 }
 327 
 328         private:
 329                 const fun_type pmf;
 330         };
 331 
 332         template<typename RetType,typename ObjType,typename Arg1>
 333         class copy_mem_fun1_ref_t {
 334         public:
 335                 typedef typename ObjType object_type;
 336                 typedef typename RetType result_type;
 337                 typedef typename Arg1 first_argument_type;
 338                 typedef RetType (__fastcall ObjType::*fun_type)(const Arg1 &);
 339 
 340                 explicit __stdcall copy_mem_fun1_ref_t(const fun_type p) noexcept(true)
 341                 : pmf(p) {
 342                         assert(pmf);
 343                 }
 344                 __stdcall copy_mem_fun1_ref_t(const copy_mem_fun1_ref_t &p) noexcept(true)
 345                 : pmf(p.pmf) {
 346                         assert(pmf);
 347                 }
 348                 __stdcall ~copy_mem_fun1_ref_t(void) noexcept(true) {
 349                 }
 350 
 351                 RetType __fastcall operator()(const ObjType &p,const Arg1 &b) const {
 352                         return (ObjType(p).*pmf)(b);
 353                 }
 354                 RetType __fastcall operator()(ObjType &p,const Arg1 &b) const {
 355                         return (ObjType(p).*pmf)(b);
 356                 }
 357 
 358         private:
 359                 const fun_type pmf;
 360         };
 361 
 362         template<typename RetType,typename ObjType,typename Arg1,typename Arg2>
 363         class copy_mem_fun2_ref_t {
 364         public:
 365                 typedef typename ObjType object_type;
 366                 typedef typename RetType result_type;
 367                 typedef typename Arg1 first_argument_type;
 368                 typedef typename Arg2 second_argument_type;
 369                 typedef RetType (__fastcall ObjType::*fun_type)(const Arg1 &,const Arg2 &);
 370 
 371                 explicit __stdcall copy_mem_fun2_ref_t(const fun_type p) noexcept(true)
 372                 : pmf(p) {
 373                         assert(pmf);
 374                 }
 375                 __stdcall copy_mem_fun2_ref_t(const copy_mem_fun2_ref_t &p) noexcept(true)
 376                 : pmf(p.pmf) {
 377                         assert(pmf);
 378                 }
 379                 __stdcall ~copy_mem_fun2_ref_t(void) noexcept(true) {
 380                 }
 381 
 382                 RetType __fastcall operator()(const ObjType &p,const Arg1 &b,const Arg2 &c) const {
 383                         return (ObjType(p).*pmf)(b,c);
 384                 }
 385                 RetType __fastcall operator()(ObjType &p,const Arg1 &b,const Arg2 &c) const {
 386                         return (ObjType(p).*pmf)(b,c);
 387                 }
 388 
 389         private:
 390                 const fun_type pmf;
 391         };
 392 
 393         template<typename RetType,typename ObjType,typename Arg1>
 394         class const_mem_fun1_t {
 395         public:
 396                 typedef typename ObjType object_type;
 397                 typedef typename RetType result_type;
 398                 typedef typename Arg1 first_argument_type;
 399                 typedef RetType (__fastcall ObjType::*fun_type)(const Arg1) const;
 400 
 401                 explicit __stdcall const_mem_fun1_t(const fun_type p) noexcept(true)
 402                 : pmf(p) {
 403                         assert(pmf);
 404                 }
 405                 __stdcall const_mem_fun1_t(const const_mem_fun1_t &p) noexcept(true)
 406                 : pmf(p.pmf) {
 407                         assert(pmf);
 408                 }
 409                 __stdcall ~const_mem_fun1_t(void) noexcept(true) {
 410                 }
 411 
 412                 RetType __fastcall operator()(const ObjType &p,const Arg1 b) const {
 413                         return (p.*pmf)(b);
 414                 }
 415                 RetType __fastcall operator()(ObjType &p,const Arg1 b) const {
 416                         return (p.*pmf)(b);
 417                 }
 418 
 419         private:
 420                 const fun_type pmf;
 421         };
 422 
 423         template<typename RetType,typename ObjType,typename Arg1>
 424         class mem_fun1_t {
 425         public:
 426                 typedef typename ObjType object_type;
 427                 typedef typename RetType result_type;
 428                 typedef typename Arg1 first_argument_type;
 429                 typedef RetType (__fastcall ObjType::*fun_type)(const Arg1);
 430 
 431                 explicit __stdcall mem_fun1_t(const fun_type p) noexcept(true)
 432                 : pmf(p) {
 433                         assert(pmf);
 434                 }
 435                 __stdcall mem_fun1_t(const mem_fun1_t &p) noexcept(true)
 436                 : pmf(p.pmf) {
 437                         assert(pmf);
 438                 }
 439                 __stdcall ~mem_fun1_t(void) noexcept(true) {
 440                 }
 441 
 442                 RetType __fastcall operator()(const Arg1 a) const {
 443                         return (obj.*pmf)(a);
 444                 }
 445 
 446                 RetType __fastcall operator()(const Arg1 a) {
 447                         return (obj.*pmf)(a);
 448                 }
 449 
 450         private:
 451                 fun_type pmf;
 452                 ObjType obj;
 453         };
 454 
 455         template<typename RetType,typename ObjType,typename Arg1>
 456         class copy_mem_fun1_t {
 457         public:
 458                 typedef typename ObjType object_type;
 459                 typedef typename RetType result_type;
 460                 typedef typename Arg1 first_argument_type;
 461                 typedef RetType (__fastcall ObjType::*fun_type)(const Arg1);
 462 
 463                 explicit __stdcall copy_mem_fun1_t(const fun_type p) noexcept(true)
 464                 : pmf(p) {
 465                         assert(pmf);
 466                 }
 467                 __stdcall copy_mem_fun1_t(const copy_mem_fun1_t &p) noexcept(true)
 468                 : pmf(p.pmf) {
 469                         assert(pmf);
 470                 }
 471                 __stdcall ~copy_mem_fun1_t(void) noexcept(true) {
 472                 }
 473 
 474                 RetType __fastcall operator()(ObjType &p,const Arg1 b) const {
 475                         return (p.*pmf)(b);
 476                 }
 477                 RetType __fastcall operator()(ObjType &p,const Arg1 b) {
 478                         return (p.*pmf)(b);
 479                 }
 480 
 481         private:
 482                 const fun_type pmf;
 483         };
 484 
 485 /*
 486 
 487   Non-member function functors.
 488 
 489 */
 490 
 491         template<typename RetType,typename Arg1T>
 492         class ptr_fun_ref_t {
 493         public:
 494                 typedef typename RetType object_type;
 495                 typedef typename RetType result_type;
 496                 typedef typename Arg1T first_argument_type;
 497                 typedef RetType (__fastcall *fun_type)(const Arg1T &);
 498 
 499                 explicit __stdcall ptr_fun_ref_t(const fun_type p) noexcept(true)
 500                 : pmf(p) {
 501                         assert(pmf);
 502                 }
 503                 __stdcall ptr_fun_ref_t(const ptr_fun_ref_t &p) noexcept(true)
 504                 : pmf(p.pmf) {
 505                         assert(pmf);
 506                 }
 507                 __stdcall ~ptr_fun_ref_t(void) noexcept(true) {
 508                 }
 509 
 510                 RetType __fastcall operator()(const Arg1T &a) const {
 511                         return (*pmf)(a);
 512                 }
 513 
 514         private:
 515                 const fun_type pmf;
 516         };
 517 
 518         template<typename RetType,typename Arg1T,typename Arg2T>
 519         class ptr_fun2_ref_t {
 520         public:
 521                 typedef typename RetType object_type;
 522                 typedef typename RetType result_type;
 523                 typedef typename Arg1T first_argument_type;
 524                 typedef typename Arg2T second_argument_type;
 525                 typedef RetType (__fastcall *fun_type)(const Arg1T &,const Arg2T &);
 526 
 527                 explicit __stdcall ptr_fun2_ref_t(const fun_type p) noexcept(true)
 528                 : pmf(p) {
 529                         assert(pmf);
 530                 }
 531                 __stdcall ptr_fun2_ref_t(const ptr_fun2_ref_t &p) noexcept(true)
 532                 : pmf(p.pmf) {
 533                         assert(pmf);
 534                 }
 535                 __stdcall ~ptr_fun2_ref_t(void) noexcept(true) {
 536                 }
 537 
 538                 RetType __fastcall operator()(const Arg1T &a,const Arg2T &b) const {
 539                         return (*pmf)(a,b);
 540                 }
 541 
 542         private:
 543                 const fun_type pmf;
 544         };
 545 
 546         template<typename RetType,typename Arg1T,typename Arg2T,typename Arg3T>
 547         class ptr_fun3_ref_t {
 548         public:
 549                 typedef typename RetType object_type;
 550                 typedef typename RetType result_type;
 551                 typedef typename Arg1T first_argument_type;
 552                 typedef typename Arg2T second_argument_type;
 553                 typedef typename Arg3T third_argument_type;
 554                 typedef RetType (__fastcall *fun_type)(const Arg1T &,const Arg2T &,const Arg3T &);
 555 
 556                 explicit __stdcall ptr_fun3_ref_t(const fun_type p) noexcept(true)
 557                 : pmf(p) {
 558                         assert(pmf);
 559                 }
 560                 __stdcall ptr_fun3_ref_t(const ptr_fun3_ref_t &p) noexcept(true)
 561                 : pmf(p.pmf) {
 562                         assert(pmf);
 563                 }
 564                 __stdcall ~ptr_fun3_ref_t(void) noexcept(true) {
 565                 }
 566 
 567                 RetType __fastcall operator()(const Arg1T &a,const Arg2T &b,const Arg3T &c) const {
 568                         return (*pmf)(a,b,c);
 569                 }
 570 
 571         private:
 572                 const fun_type pmf;
 573         };
 574 
 575         template<typename RetType,typename Arg1T,typename Arg2T,typename Arg3T,typename Arg4T>
 576         class ptr_fun4_ref_t {
 577         public:
 578                 typedef typename RetType object_type;
 579                 typedef typename RetType result_type;
 580                 typedef typename Arg1T first_argument_type;
 581                 typedef typename Arg2T second_argument_type;
 582                 typedef typename Arg3T third_argument_type;
 583                 typedef typename Arg4T fourth_argument_type;
 584                 typedef RetType (__fastcall *fun_type)(const Arg1T &,const Arg2T &,const Arg3T &);
 585 
 586                 explicit __stdcall ptr_fun4_ref_t(const fun_type p) noexcept(true)
 587                 : pmf(p) {
 588                         assert(pmf);
 589                 }
 590                 __stdcall ptr_fun4_ref_t(const ptr_fun4_ref_t &p) noexcept(true)
 591                 : pmf(p.pmf) {
 592                         assert(pmf);
 593                 }
 594                 __stdcall ~ptr_fun4_ref_t(void) noexcept(true) {
 595                 }
 596 
 597                 RetType __fastcall operator()(const Arg1T &a,const Arg2T &b,const Arg3T &c,const Arg4T &d) const {
 598                         return (*pmf)(a,b,c,d);
 599                 }
 600 
 601         private:
 602                 const fun_type pmf;
 603         };
 604 
 605         template<typename RetType,typename Arg1T>
 606         class ptr_fun_t {
 607         public:
 608                 typedef typename RetType object_type;
 609                 typedef typename RetType result_type;
 610                 typedef typename Arg1T first_argument_type;
 611                 typedef RetType (__fastcall *fun_type)(const Arg1T);
 612 
 613                 explicit __stdcall ptr_fun_t(const fun_type p) noexcept(true)
 614                 : pmf(p) {
 615                         assert(pmf);
 616                 }
 617                  __stdcall ptr_fun_t(const ptr_fun_t &p) noexcept(true)
 618                 : pmf(p.pmf) {
 619                         assert(pmf);
 620                 }
 621                  __stdcall ~ptr_fun_t(void) noexcept(true) {
 622                 }
 623 
 624                 RetType __fastcall operator()(const Arg1T a) const {
 625                         return (*pmf)(a);
 626                 }
 627 
 628         private:
 629                 const fun_type pmf;
 630         };
 631 
 632         template<typename RetType,typename Arg1T,typename Arg2T>
 633         class ptr_fun2_t {
 634         public:
 635                 typedef typename RetType object_type;
 636                 typedef typename RetType result_type;
 637                 typedef typename Arg1T first_argument_type;
 638                 typedef typename Arg2T second_argument_type;
 639                 typedef RetType (__fastcall *fun_type)(const Arg1T,const Arg2T);
 640 
 641                 explicit __stdcall ptr_fun2_t(const fun_type p) noexcept(true)
 642                 : pmf(p) {
 643                         assert(pmf);
 644                 }
 645                 __stdcall ptr_fun2_t(const ptr_fun2_t &p) noexcept(true)
 646                 : pmf(p.pmf) {
 647                         assert(pmf);
 648                 }
 649                 __stdcall ~ptr_fun2_t(void) noexcept(true) {
 650                 }
 651 
 652                 RetType __fastcall operator()(const Arg1T a,const Arg2T b) const {
 653                         return (pmf)(a,b);
 654                 }
 655 
 656         private:
 657                 const fun_type pmf;
 658         };
 659 
 660 /*
 661 
 662   Binders.
 663 
 664 */
 665 
 666         template<typename ArgType>
 667         struct NullCrack : std::unary_function<ArgType, ArgType> {
 668                 typedef typename std::unary_function<ArgType, ArgType>::result_type result_type;
 669                 typedef typename std::unary_function<ArgType, ArgType>::argument_type argument_type;
 670 
 671                 const result_type & __fastcall operator()(const argument_type &r) const noexcept(true) {
 672                         return r;
 673                 }
 674                 result_type & __fastcall operator()(argument_type &r) const noexcept(true) {
 675                         return r;
 676                 }
 677         };
 678 
 679         struct no_args {
 680         };
 681         struct one_arg {
 682         };
 683         struct two_args {
 684         };
 685         struct three_args {
 686         };
 687         struct four_args {
 688         };
 689 
 690         template<typename FnType>
 691         class binder0args {
 692         public:
 693                 typedef no_args num_args;
 694                 typedef typename FnType::object_type object_type;
 695                 typedef typename FnType::result_type result_type;
 696                 typedef FnType fun_type;
 697 
 698                 __stdcall binder0args(const FnType &x) noexcept(true)
 699                 : op(x) {
 700                 }
 701                 __stdcall binder0args(const binder0args &x) noexcept(true)
 702                 : op(x.op) {
 703                 }
 704                 __stdcall ~binder0args(void) noexcept(true) {
 705                 }
 706 
 707                 const FnType & __fastcall Op(void) const noexcept(true) {
 708                         return op;
 709                 }
 710 
 711                 result_type __fastcall operator()(void) const {
 712                         return op();
 713                 }
 714                 result_type __fastcall operator()(void) {
 715                         return op();
 716                 }
 717 
 718         private:
 719                 const FnType op;
 720         };
 721 
 722         template<typename FnType,typename Arg1T,template<class> class Cracker1st=NullCrack>
 723         class binder1st {
 724         public:
 725                 typedef one_arg num_args;
 726                 typedef typename FnType::object_type object_type;
 727                 typedef typename FnType::result_type result_type;
 728                 typedef FnType fun_type;
 729                 typedef Arg1T first_argument_type;
 730                 typedef Cracker1st<first_argument_type> crkd_first_argument_type;
 731 
 732                 const first_argument_type arg1;
 733 
 734                 __stdcall binder1st(const FnType &x,const first_argument_type &v) noexcept(true)
 735                 : op(x),arg1(v) {
 736                 }
 737                 __stdcall binder1st(const binder1st &x) noexcept(true)
 738                 : op(x.op),arg1(x.arg1) {
 739                 }
 740                 __stdcall ~binder1st(void) noexcept(true) {
 741                 }
 742 
 743                 const FnType & __fastcall Op(void) const noexcept(true) {
 744                         return op;
 745                 }
 746 
 747                 result_type __fastcall operator()(void) const {
 748                         return op(crkd_first_argument_type()(arg1));
 749                 }
 750                 result_type __fastcall operator()(void) {
 751                         return op(crkd_first_argument_type()(arg1));
 752                 }
 753 
 754         private:
 755                 FnType op;
 756         };
 757 
 758         template<typename FnType,typename Arg1T,typename Arg2T,template<class> class Cracker1st=NullCrack,template<class> class Cracker2nd=NullCrack>
 759         class binder2args {
 760         public:
 761                 typedef two_args num_args;
 762                 typedef typename FnType::object_type object_type;
 763                 typedef typename FnType::result_type result_type;
 764                 typedef FnType fun_type;
 765                 typedef Arg1T first_argument_type;
 766                 typedef Arg2T second_argument_type;
 767                 typedef Cracker1st<first_argument_type> crkd_first_argument_type;
 768                 typedef Cracker2nd<second_argument_type> crkd_second_argument_type;
 769 
 770                 first_argument_type arg1;
 771                 const second_argument_type arg2;
 772 
 773                 __stdcall binder2args(const FnType &x,const first_argument_type &v,const second_argument_type &b) noexcept(true)
 774                 : op(x),arg1(v),arg2(b) {
 775                 }
 776                 __stdcall binder2args(const binder2args &x) noexcept(true)
 777                 : op(x.op),arg1(x.arg1),arg2(x.arg2) {
 778                 }
 779                 __stdcall ~binder2args(void) noexcept(true) {
 780                 }
 781 
 782                 const FnType & __fastcall Op(void) const noexcept(true) {
 783                         return op;
 784                 }
 785 
 786                 result_type __fastcall operator()(void) const {
 787                         return op(crkd_first_argument_type()(arg1),crkd_second_argument_type()(arg2));
 788                 }
 789                 result_type __fastcall operator()(void) {
 790                         return op(crkd_first_argument_type()(arg1),crkd_second_argument_type()(arg2));
 791                 }
 792 
 793         private:
 794                 FnType op;
 795         };
 796 
 797         template<typename FnType,typename Arg1T,typename Arg2T,typename Arg3T,template<class> class Cracker1st=NullCrack,template<class> class Cracker2nd=NullCrack,template<class> class Cracker3rd=NullCrack>
 798         class binder3args {
 799         public:
 800                 typedef three_args num_args;
 801                 typedef typename FnType::object_type object_type;
 802                 typedef typename FnType::result_type result_type;
 803                 typedef FnType fun_type;
 804                 typedef Arg1T first_argument_type;
 805                 typedef Arg2T second_argument_type;
 806                 typedef Arg3T third_argument_type;
 807                 typedef Cracker1st<first_argument_type> crkd_first_argument_type;
 808                 typedef Cracker2nd<second_argument_type> crkd_second_argument_type;
 809                 typedef Cracker3rd<third_argument_type> crkd_third_argument_type;
 810 
 811                 const first_argument_type arg1;
 812                 const second_argument_type arg2;
 813                 const third_argument_type arg3;
 814 
 815                 __stdcall binder3args(const FnType &x,const first_argument_type &v,const second_argument_type &b,const third_argument_type &c) noexcept(true)
 816                 : op(x),arg1(v),arg2(b),arg3(c) {
 817                 }
 818                 __stdcall binder3args(const binder3args &x) noexcept(true)
 819                 : op(x.op),arg1(x.arg1),arg2(x.arg2),arg3(x.arg3) {
 820                 }
 821                 __stdcall ~binder3args(void) noexcept(true) {
 822                 }
 823 
 824                 const FnType & __fastcall Op(void) const noexcept(true) {
 825                         return op;
 826                 }
 827 
 828                 result_type __fastcall operator()(void) const {
 829                         return op(crkd_first_argument_type()(arg1),crkd_second_argument_type()(arg2),crkd_third_argument_type()(arg3));
 830                 }
 831                 result_type __fastcall operator()(void) {
 832                         return op(crkd_first_argument_type()(arg1),crkd_second_argument_type()(arg2),crkd_third_argument_type()(arg3));
 833                 }
 834 
 835         private:
 836                 const FnType op;
 837         };
 838 
 839         template<typename FnType,typename Arg1T,typename Arg2T,typename Arg3T,typename Arg4T,template<class> class Cracker1st=NullCrack,template<class> class Cracker2nd=NullCrack,template<class> class Cracker3rd=NullCrack,template<class> class Cracker4th=NullCrack>
 840         class binder4args {
 841         public:
 842                 typedef four_args num_args;
 843                 typedef typename FnType::object_type object_type;
 844                 typedef typename FnType::result_type result_type;
 845                 typedef FnType fun_type;
 846                 typedef Arg1T first_argument_type;
 847                 typedef Arg2T second_argument_type;
 848                 typedef Arg3T third_argument_type;
 849                 typedef Arg3T fourth_argument_type;
 850                 typedef Cracker1st<first_argument_type> crkd_first_argument_type;
 851                 typedef Cracker2nd<second_argument_type> crkd_second_argument_type;
 852                 typedef Cracker3rd<third_argument_type> crkd_third_argument_type;
 853                 typedef Cracker4th<fourth_argument_type> crkd_fourth_argument_type;
 854 
 855                 const first_argument_type arg1;
 856                 const second_argument_type arg2;
 857                 const third_argument_type arg3;
 858                 const fourth_argument_type arg4;
 859 
 860                 __stdcall binder4args(const FnType &x,const first_argument_type &v,const second_argument_type &b,const third_argument_type &c,const fourth_argument_type &d) noexcept(true)
 861                 : op(x),arg1(v),arg2(b),arg3(c),arg4(d) {
 862                 }
 863                 __stdcall binder4args(const binder4args &x) noexcept(true)
 864                 : op(x.op),arg1(x.arg1),arg2(x.arg2),arg3(x.arg3),arg4(x.arg4) {
 865                 }
 866                 __stdcall ~binder4args(void) noexcept(true) {
 867                 }
 868 
 869                 const FnType & __fastcall Op(void) const noexcept(true) {
 870                         return op;
 871                 }
 872 
 873                 result_type __fastcall operator()(void) const {
 874                         return op(crkd_first_argument_type()(arg1),crkd_second_argument_type()(arg2),crkd_third_argument_type()(arg3),crkd_fourth_argument_type()(arg4));
 875                 }
 876                 result_type __fastcall operator()(void) {
 877                         return op(crkd_first_argument_type()(arg1),crkd_second_argument_type()(arg2),crkd_third_argument_type()(arg3),crkd_fourth_argument_type()(arg4));
 878                 }
 879 
 880         private:
 881                 const FnType op;
 882         };
 883 
 884 }
 885 
 886 #endif

/* [<][>][^][v][top][bottom][index][help] */