make_adaptable.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #ifndef BOOST_BIND_MAKE_ADAPTABLE_HPP_INCLUDED
  2. #define BOOST_BIND_MAKE_ADAPTABLE_HPP_INCLUDED
  3. //
  4. // make_adaptable.hpp
  5. //
  6. // Copyright (c) 2002 Peter Dimov and Multi Media Ltd.
  7. //
  8. // Distributed under the Boost Software License, Version 1.0. (See
  9. // accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. //
  12. namespace boost
  13. {
  14. namespace _bi
  15. {
  16. template<class R, class F> class af0
  17. {
  18. public:
  19. typedef R result_type;
  20. explicit af0(F f): f_(f)
  21. {
  22. }
  23. result_type operator()()
  24. {
  25. return f_();
  26. }
  27. result_type operator()() const
  28. {
  29. return f_();
  30. }
  31. private:
  32. F f_;
  33. };
  34. template<class R, class A1, class F> class af1
  35. {
  36. public:
  37. typedef R result_type;
  38. typedef A1 argument_type;
  39. typedef A1 arg1_type;
  40. explicit af1(F f): f_(f)
  41. {
  42. }
  43. result_type operator()(A1 a1)
  44. {
  45. return f_(a1);
  46. }
  47. result_type operator()(A1 a1) const
  48. {
  49. return f_(a1);
  50. }
  51. private:
  52. F f_;
  53. };
  54. template<class R, class A1, class A2, class F> class af2
  55. {
  56. public:
  57. typedef R result_type;
  58. typedef A1 first_argument_type;
  59. typedef A2 second_argument_type;
  60. typedef A1 arg1_type;
  61. typedef A2 arg2_type;
  62. explicit af2(F f): f_(f)
  63. {
  64. }
  65. result_type operator()(A1 a1, A2 a2)
  66. {
  67. return f_(a1, a2);
  68. }
  69. result_type operator()(A1 a1, A2 a2) const
  70. {
  71. return f_(a1, a2);
  72. }
  73. private:
  74. F f_;
  75. };
  76. template<class R, class A1, class A2, class A3, class F> class af3
  77. {
  78. public:
  79. typedef R result_type;
  80. typedef A1 arg1_type;
  81. typedef A2 arg2_type;
  82. typedef A3 arg3_type;
  83. explicit af3(F f): f_(f)
  84. {
  85. }
  86. result_type operator()(A1 a1, A2 a2, A3 a3)
  87. {
  88. return f_(a1, a2, a3);
  89. }
  90. result_type operator()(A1 a1, A2 a2, A3 a3) const
  91. {
  92. return f_(a1, a2, a3);
  93. }
  94. private:
  95. F f_;
  96. };
  97. template<class R, class A1, class A2, class A3, class A4, class F> class af4
  98. {
  99. public:
  100. typedef R result_type;
  101. typedef A1 arg1_type;
  102. typedef A2 arg2_type;
  103. typedef A3 arg3_type;
  104. typedef A4 arg4_type;
  105. explicit af4(F f): f_(f)
  106. {
  107. }
  108. result_type operator()(A1 a1, A2 a2, A3 a3, A4 a4)
  109. {
  110. return f_(a1, a2, a3, a4);
  111. }
  112. result_type operator()(A1 a1, A2 a2, A3 a3, A4 a4) const
  113. {
  114. return f_(a1, a2, a3, a4);
  115. }
  116. private:
  117. F f_;
  118. };
  119. } // namespace _bi
  120. template<class R, class F> _bi::af0<R, F> make_adaptable(F f)
  121. {
  122. return _bi::af0<R, F>(f);
  123. }
  124. template<class R, class A1, class F> _bi::af1<R, A1, F> make_adaptable(F f)
  125. {
  126. return _bi::af1<R, A1, F>(f);
  127. }
  128. template<class R, class A1, class A2, class F> _bi::af2<R, A1, A2, F> make_adaptable(F f)
  129. {
  130. return _bi::af2<R, A1, A2, F>(f);
  131. }
  132. template<class R, class A1, class A2, class A3, class F> _bi::af3<R, A1, A2, A3, F> make_adaptable(F f)
  133. {
  134. return _bi::af3<R, A1, A2, A3, F>(f);
  135. }
  136. template<class R, class A1, class A2, class A3, class A4, class F> _bi::af4<R, A1, A2, A3, A4, F> make_adaptable(F f)
  137. {
  138. return _bi::af4<R, A1, A2, A3, A4, F>(f);
  139. }
  140. } // namespace boost
  141. #endif // #ifndef BOOST_BIND_MAKE_ADAPTABLE_HPP_INCLUDED