bind_member_function.hpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*=============================================================================
  2. Copyright (c) 2001-2007 Joel de Guzman
  3. Copyright (c) 2014 John Fletcher
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. #if !BOOST_PHOENIX_IS_ITERATING
  8. #include <boost/utility/enable_if.hpp>
  9. #include <boost/type_traits/is_member_function_pointer.hpp>
  10. #include <boost/phoenix/core/expression.hpp>
  11. #include <boost/phoenix/core/reference.hpp>
  12. #include <boost/phoenix/core/detail/function_eval.hpp>
  13. #include <boost/phoenix/bind/detail/cpp03/member_function_ptr.hpp>
  14. namespace boost { namespace phoenix
  15. {
  16. template <typename RT, typename ClassT, typename ClassA>
  17. inline
  18. typename boost::lazy_enable_if<
  19. boost::is_member_function_pointer<RT (ClassT::*)()>,
  20. typename detail::expression::function_eval<
  21. detail::member_function_ptr<0, RT, RT(ClassT::*)()>
  22. , ClassA >
  23. >::type const
  24. bind(RT(ClassT::*f)(), ClassA const& obj)
  25. {
  26. typedef detail::member_function_ptr<0, RT, RT(ClassT::*)()> fp_type;
  27. return
  28. detail::expression::function_eval<fp_type, ClassA>::make(
  29. fp_type(f)
  30. , obj
  31. );
  32. }
  33. template <typename RT, typename ClassT, typename ClassA>
  34. inline
  35. typename boost::lazy_enable_if<
  36. boost::is_member_function_pointer<RT (ClassT::*)()>,
  37. typename detail::expression::function_eval<
  38. detail::member_function_ptr<0, RT, RT(ClassT::*)() const>
  39. , ClassA >
  40. >::type const
  41. bind(RT(ClassT::*f)() const, ClassA const& obj)
  42. {
  43. typedef
  44. detail::member_function_ptr<0, RT, RT(ClassT::*)() const>
  45. fp_type;
  46. return
  47. detail::expression::function_eval<fp_type, ClassA>::make(
  48. fp_type(f)
  49. , obj
  50. );
  51. }
  52. template <typename RT, typename ClassT>
  53. inline
  54. typename detail::expression::function_eval<
  55. detail::member_function_ptr<0, RT, RT(ClassT::*)()>
  56. , ClassT
  57. >::type const
  58. bind(RT(ClassT::*f)(), ClassT& obj)
  59. {
  60. typedef detail::member_function_ptr<0, RT, RT(ClassT::*)()> fp_type;
  61. return
  62. detail::expression::function_eval<
  63. fp_type
  64. , ClassT
  65. >::make(
  66. fp_type(f)
  67. , obj
  68. );
  69. }
  70. template <typename RT, typename ClassT>
  71. inline
  72. typename detail::expression::function_eval<
  73. detail::member_function_ptr<0, RT, RT(ClassT::*)() const>
  74. , ClassT
  75. >::type const
  76. bind(RT(ClassT::*f)() const, ClassT& obj)
  77. {
  78. typedef detail::member_function_ptr<0, RT, RT(ClassT::*)() const> fp_type;
  79. return
  80. detail::expression::function_eval<
  81. fp_type
  82. , ClassT
  83. >::make(
  84. fp_type(f)
  85. , obj
  86. );
  87. }
  88. #if !defined(BOOST_PHOENIX_DONT_USE_PREPROCESSED_FILES)
  89. #include <boost/phoenix/bind/detail/cpp03/preprocessed/bind_member_function.hpp>
  90. #else
  91. #if defined(__WAVE__) && defined (BOOST_PHOENIX_CREATE_PREPROCESSED_FILES)
  92. #pragma wave option(preserve: 2, line: 0, output: "preprocessed/bind_member_function_" BOOST_PHOENIX_LIMIT_STR ".hpp")
  93. #endif
  94. /*=============================================================================
  95. Copyright (c) 2001-2007 Joel de Guzman
  96. Distributed under the Boost Software License, Version 1.0. (See accompanying
  97. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  98. ==============================================================================*/
  99. #if defined(__WAVE__) && defined(BOOST_PHOENIX_CREATE_PREPROCESSED_FILES)
  100. #pragma wave option(preserve: 1)
  101. #endif
  102. #define BOOST_PHOENIX_ITERATION_PARAMS \
  103. (3, (1, BOOST_PP_DEC(BOOST_PHOENIX_ACTOR_LIMIT), \
  104. <boost/phoenix/bind/detail/cpp03/bind_member_function.hpp>))
  105. #include BOOST_PHOENIX_ITERATE()
  106. #if defined(__WAVE__) && defined (BOOST_PHOENIX_CREATE_PREPROCESSED_FILES)
  107. #pragma wave option(output: null)
  108. #endif
  109. #endif
  110. }}
  111. #else
  112. template <
  113. typename RT
  114. , typename ClassT
  115. , BOOST_PP_ENUM_PARAMS(BOOST_PHOENIX_ITERATION, typename T)
  116. , typename ClassA
  117. , BOOST_PHOENIX_typename_A
  118. >
  119. inline
  120. typename detail::expression::function_eval<
  121. detail::member_function_ptr<
  122. BOOST_PHOENIX_ITERATION
  123. , RT
  124. , RT(ClassT::*)(BOOST_PP_ENUM_PARAMS(BOOST_PHOENIX_ITERATION, T))
  125. >
  126. , ClassA
  127. , BOOST_PHOENIX_A
  128. >::type const
  129. bind(
  130. RT(ClassT::*f)(BOOST_PP_ENUM_PARAMS(BOOST_PHOENIX_ITERATION, T))
  131. , ClassA const & obj
  132. , BOOST_PHOENIX_A_const_ref_a
  133. )
  134. {
  135. typedef detail::member_function_ptr<
  136. BOOST_PHOENIX_ITERATION
  137. , RT
  138. , RT(ClassT::*)(BOOST_PP_ENUM_PARAMS(BOOST_PHOENIX_ITERATION, T))
  139. > fp_type;
  140. return
  141. detail::expression::function_eval<
  142. fp_type
  143. , ClassA
  144. , BOOST_PHOENIX_A
  145. >::make(
  146. fp_type(f)
  147. , obj
  148. , BOOST_PHOENIX_a
  149. );
  150. }
  151. template <
  152. typename RT
  153. , typename ClassT
  154. , BOOST_PP_ENUM_PARAMS(BOOST_PHOENIX_ITERATION, typename T)
  155. , typename ClassA
  156. , BOOST_PHOENIX_typename_A
  157. >
  158. inline
  159. typename detail::expression::function_eval<
  160. detail::member_function_ptr<
  161. BOOST_PHOENIX_ITERATION
  162. , RT
  163. , RT(ClassT::*)(BOOST_PP_ENUM_PARAMS(BOOST_PHOENIX_ITERATION, T)) const
  164. >
  165. , ClassA
  166. , BOOST_PHOENIX_A
  167. >::type const
  168. bind(
  169. RT(ClassT::*f)(BOOST_PP_ENUM_PARAMS(BOOST_PHOENIX_ITERATION, T)) const
  170. , ClassA const & obj
  171. , BOOST_PHOENIX_A_const_ref_a
  172. )
  173. {
  174. typedef detail::member_function_ptr<
  175. BOOST_PHOENIX_ITERATION
  176. , RT
  177. , RT(ClassT::*)(BOOST_PP_ENUM_PARAMS(BOOST_PHOENIX_ITERATION, T)) const
  178. > fp_type;
  179. return
  180. detail::expression::function_eval<
  181. fp_type
  182. , ClassA
  183. , BOOST_PHOENIX_A
  184. >::make(
  185. fp_type(f)
  186. , obj
  187. , BOOST_PHOENIX_a
  188. );
  189. }
  190. template <
  191. typename RT
  192. , typename ClassT
  193. , BOOST_PP_ENUM_PARAMS(BOOST_PHOENIX_ITERATION, typename T)
  194. , BOOST_PHOENIX_typename_A
  195. >
  196. inline
  197. typename detail::expression::function_eval<
  198. detail::member_function_ptr<
  199. BOOST_PHOENIX_ITERATION
  200. , RT
  201. , RT(ClassT::*)(BOOST_PP_ENUM_PARAMS(BOOST_PHOENIX_ITERATION, T))
  202. >
  203. , ClassT
  204. , BOOST_PHOENIX_A
  205. >::type const
  206. bind(
  207. RT(ClassT::*f)(BOOST_PP_ENUM_PARAMS(BOOST_PHOENIX_ITERATION, T))
  208. , ClassT & obj
  209. , BOOST_PHOENIX_A_const_ref_a
  210. )
  211. {
  212. typedef detail::member_function_ptr<
  213. BOOST_PHOENIX_ITERATION
  214. , RT
  215. , RT(ClassT::*)(BOOST_PP_ENUM_PARAMS(BOOST_PHOENIX_ITERATION, T))
  216. > fp_type;
  217. return
  218. detail::expression::function_eval<
  219. fp_type
  220. , ClassT
  221. , BOOST_PHOENIX_A
  222. >::make(
  223. fp_type(f)
  224. , obj
  225. , BOOST_PHOENIX_a
  226. );
  227. }
  228. #endif