home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / stl453up.zip / stl453fx / test / regression / fadapter.h < prev    next >
C/C++ Source or Header  |  2002-04-29  |  2KB  |  82 lines

  1. #ifndef    _fadapter_h_
  2. #define    _fadapter_h_
  3.  
  4. #include <functional>
  5.  
  6. // used as adaptor's return/argument type, 
  7. // to allow binders/composers usage
  8. struct __void_tag {};
  9.  
  10. # if !defined (STLPORT) || defined (__STL_USE_NAMESPACES)
  11. using std::unary_function;
  12. # endif
  13.  
  14. template <class Result>
  15. class pointer_to_void_function {
  16. protected:
  17.     Result (*ptr)();
  18. public:
  19.     explicit pointer_to_void_function(Result (*x)()) : ptr(x) {}
  20.     Result operator()() const { return ptr(); }
  21.     Result operator()(__void_tag) const { return ptr(); }
  22. };
  23.  
  24. // to feed composers
  25. template <class Arg1>
  26. struct projectvoid :
  27.   public unary_function<Arg1,__void_tag> {
  28.   __void_tag operator()(const Arg1& x) const { return __void_tag(); }
  29. };
  30.  
  31. # if !defined (_STLP_MEMBER_POINTER_PARAM_BUG)
  32.  
  33. template <class Result>
  34. pointer_to_void_function<Result> ptr_fun(Result (*x)()) {
  35.     return pointer_to_void_function<Result>(x);
  36. }
  37.  
  38. // alternate name
  39. template <class Result>
  40. pointer_to_void_function<Result> ptr_gen(Result (*x)()) {
  41.     return pointer_to_void_function<Result>(x);
  42. }
  43.  
  44. # endif /*  !defined (__STL_MEMBER_POINTER_PARAM_BUG) */
  45.  
  46.  
  47. template <class Arg>
  48. class    pointer_to_unary_procedure /* :public unary_function<Arg, __void_tag> */ {
  49. protected:
  50.     typedef void    (*fun_type)(Arg);
  51.         fun_type ptr;
  52. public:
  53.     typedef Arg argument_type;
  54.     pointer_to_unary_procedure()    {}
  55.     pointer_to_unary_procedure(fun_type x) : ptr(x)    {}
  56.     void    operator() (Arg x) const    { ptr(x); }
  57. };
  58. template <class Arg>
  59. inline pointer_to_unary_procedure<Arg> ptr_proc(void (*x)(Arg)) {
  60.     return pointer_to_unary_procedure<Arg>(x);
  61. }
  62.  
  63. template <class Arg1, class Arg2>
  64. class   pointer_to_binary_procedure /* : public unary_function<Arg1, Arg2, __void_tag> */ {
  65. protected:
  66.     typedef void    (*fun_type)(Arg1, Arg2);
  67.     fun_type ptr;
  68. public:
  69.     typedef Arg1 first_argument_type;
  70.     typedef Arg2 second_argument_type;
  71.         pointer_to_binary_procedure()    {}
  72.         pointer_to_binary_procedure(fun_type x) : ptr(x)    {}
  73.         void    operator() (Arg1 x, Arg2 y) const        { ptr(x, y); }
  74. };
  75. template <class Arg1, class Arg2>
  76. inline pointer_to_binary_procedure<Arg1, Arg2> ptr_proc(void (*x)(Arg1, Arg2)) {
  77.         return pointer_to_binary_procedure<Arg1, Arg2>(x);
  78. }
  79.  
  80. #endif
  81.  
  82.