macros.hpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. // Copyright David Abrahams, Daniel Wallin 2003.
  2. // Copyright Cromwell D. Enage 2017.
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_PARAMETER_MACROS_050412_HPP
  7. #define BOOST_PARAMETER_MACROS_050412_HPP
  8. #include <boost/parameter/config.hpp>
  9. #include <boost/preprocessor/repetition/enum_params.hpp>
  10. #if !defined(BOOST_NO_SFINAE) && \
  11. !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
  12. #define BOOST_PARAMETER_MATCH_TYPE(n, param) \
  13. , typename param::match<BOOST_PP_ENUM_PARAMS(n, T)>::type kw = param()
  14. /**/
  15. #define BOOST_PARAMETER_MATCH_TYPE_Z(z, n, param) \
  16. , typename param::match<BOOST_PP_ENUM_PARAMS_Z(z, n, T)>::type kw = param()
  17. /**/
  18. #else // SFINAE disbled, or Borland workarounds needed.
  19. #define BOOST_PARAMETER_MATCH_TYPE(n, param) , param kw = param()
  20. /**/
  21. #define BOOST_PARAMETER_MATCH_TYPE_Z(z, n, param) , param kw = param()
  22. /**/
  23. #endif // SFINAE enabled, not Borland.
  24. #include <boost/preprocessor/control/if.hpp>
  25. #include <boost/preprocessor/repetition/enum_binary_params.hpp>
  26. #include <boost/preprocessor/tuple/elem.hpp>
  27. #include <boost/preprocessor/cat.hpp>
  28. #if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  29. #define BOOST_PARAMETER_FUN_0(z, n, params) \
  30. BOOST_PP_TUPLE_ELEM(3, 0, params) BOOST_PP_TUPLE_ELEM(3, 1, params)() \
  31. { \
  32. return BOOST_PP_CAT( \
  33. BOOST_PP_TUPLE_ELEM(3, 1, params) \
  34. , _with_named_params \
  35. )(BOOST_PP_TUPLE_ELEM(3, 2, params)()()); \
  36. }
  37. /**/
  38. #include <utility>
  39. #define BOOST_PARAMETER_FUN_DECL_PARAM(z, n, p) \
  40. ::std::forward<BOOST_PP_CAT(T, n)>(BOOST_PP_CAT(p, n))
  41. /**/
  42. #include <boost/preprocessor/repetition/enum.hpp>
  43. #define BOOST_PARAMETER_FUN_DEFN_1(z, n, params) \
  44. template <BOOST_PP_ENUM_PARAMS_Z(z, n, typename T)> \
  45. BOOST_PP_TUPLE_ELEM(3, 0, params) \
  46. BOOST_PP_TUPLE_ELEM(3, 1, params)( \
  47. BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, T, && p) \
  48. BOOST_PARAMETER_MATCH_TYPE_Z( \
  49. z, n, BOOST_PP_TUPLE_ELEM(3, 2, params) \
  50. ) \
  51. ) \
  52. { \
  53. return BOOST_PP_CAT( \
  54. BOOST_PP_TUPLE_ELEM(3, 1, params) \
  55. , _with_named_params \
  56. )( \
  57. kw( \
  58. BOOST_PP_CAT(BOOST_PP_ENUM_, z)( \
  59. n, BOOST_PARAMETER_FUN_DECL_PARAM, p \
  60. ) \
  61. ) \
  62. ); \
  63. }
  64. /**/
  65. #define BOOST_PARAMETER_FUN_DECL(z, n, params) \
  66. BOOST_PP_IF( \
  67. n \
  68. , BOOST_PARAMETER_FUN_DEFN_1 \
  69. , BOOST_PARAMETER_FUN_0 \
  70. )(z, n, params)
  71. /**/
  72. #else // !defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  73. #define BOOST_PARAMETER_FUN_DEFN_0(z, n, params) \
  74. template <BOOST_PP_ENUM_PARAMS_Z(z, n, typename T)> \
  75. BOOST_PP_TUPLE_ELEM(3, 0, params) \
  76. BOOST_PP_TUPLE_ELEM(3, 1, params)( \
  77. BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, T, const& p) \
  78. BOOST_PARAMETER_MATCH_TYPE_Z( \
  79. z, n, BOOST_PP_TUPLE_ELEM(3, 2, params) \
  80. ) \
  81. ) \
  82. { \
  83. return BOOST_PP_CAT( \
  84. BOOST_PP_TUPLE_ELEM(3, 1, params) \
  85. , _with_named_params \
  86. )(kw(BOOST_PP_ENUM_PARAMS_Z(z, n, p))); \
  87. }
  88. /**/
  89. #include <boost/preprocessor/seq/seq.hpp>
  90. #define BOOST_PARAMETER_FUN_0(z, n, seq) \
  91. BOOST_PP_TUPLE_ELEM(3, 0, BOOST_PP_SEQ_HEAD(BOOST_PP_SEQ_TAIL(seq))) \
  92. BOOST_PP_TUPLE_ELEM(3, 1, BOOST_PP_SEQ_HEAD(BOOST_PP_SEQ_TAIL(seq)))() \
  93. { \
  94. return BOOST_PP_CAT( \
  95. BOOST_PP_TUPLE_ELEM( \
  96. 3, 1, BOOST_PP_SEQ_HEAD(BOOST_PP_SEQ_TAIL(seq)) \
  97. ) \
  98. , _with_named_params \
  99. )( \
  100. BOOST_PP_TUPLE_ELEM(3, 2, BOOST_PP_SEQ_HEAD(BOOST_PP_SEQ_TAIL(seq))) \
  101. ()() \
  102. ); \
  103. }
  104. /**/
  105. #include <boost/parameter/aux_/preprocessor/binary_seq_to_args.hpp>
  106. #include <boost/preprocessor/seq/size.hpp>
  107. #define BOOST_PARAMETER_FUN_DEFN_R(r, seq) \
  108. template < \
  109. BOOST_PP_ENUM_PARAMS( \
  110. BOOST_PP_SEQ_SIZE(BOOST_PP_SEQ_TAIL(seq)) \
  111. , typename T \
  112. ) \
  113. > BOOST_PP_TUPLE_ELEM(3, 0, BOOST_PP_SEQ_HEAD(seq)) \
  114. BOOST_PP_TUPLE_ELEM(3, 1, BOOST_PP_SEQ_HEAD(seq))( \
  115. BOOST_PARAMETER_AUX_PP_BINARY_SEQ_TO_ARGS( \
  116. BOOST_PP_SEQ_TAIL(seq), (T)(p) \
  117. ) \
  118. BOOST_PARAMETER_MATCH_TYPE( \
  119. BOOST_PP_SEQ_SIZE(BOOST_PP_SEQ_TAIL(seq)) \
  120. , BOOST_PP_TUPLE_ELEM(3, 2, BOOST_PP_SEQ_HEAD(seq)) \
  121. ) \
  122. ) \
  123. { \
  124. return BOOST_PP_CAT( \
  125. BOOST_PP_TUPLE_ELEM(3, 1, BOOST_PP_SEQ_HEAD(seq)) \
  126. , _with_named_params \
  127. )( \
  128. kw( \
  129. BOOST_PP_ENUM_PARAMS( \
  130. BOOST_PP_SEQ_SIZE(BOOST_PP_SEQ_TAIL(seq)), p \
  131. ) \
  132. ) \
  133. ); \
  134. }
  135. /**/
  136. #include <boost/parameter/aux_/preprocessor/binary_seq_for_each.hpp>
  137. #include <boost/preprocessor/tuple/eat.hpp>
  138. #define BOOST_PARAMETER_FUN_DEFN_1(z, n, params) \
  139. BOOST_PP_IF( \
  140. n \
  141. , BOOST_PARAMETER_AUX_PP_BINARY_SEQ_FOR_EACH_Z \
  142. , BOOST_PARAMETER_FUN_0 \
  143. )(z, n, (BOOST_PARAMETER_FUN_DEFN_R)(params))
  144. /**/
  145. #include <boost/preprocessor/comparison/less.hpp>
  146. #define BOOST_PARAMETER_FUN_DECL(z, n, params) \
  147. BOOST_PP_CAT( \
  148. BOOST_PARAMETER_FUN_DEFN_ \
  149. , BOOST_PP_LESS( \
  150. n \
  151. , BOOST_PARAMETER_EXPONENTIAL_OVERLOAD_THRESHOLD_ARITY \
  152. ) \
  153. )(z, n, params)
  154. /**/
  155. #endif // BOOST_PARAMETER_HAS_PERFECT_FORWARDING
  156. #include <boost/preprocessor/arithmetic/inc.hpp>
  157. #include <boost/preprocessor/repetition/repeat_from_to.hpp>
  158. // Generates:
  159. //
  160. // template <typename Params>
  161. // ret name ## _with_named_params(Params const&);
  162. //
  163. // template <typename T0>
  164. // ret name(
  165. // T0 && p0
  166. // , typename parameters::match<T0>::type kw = parameters()
  167. // )
  168. // {
  169. // return name ## _with_named_params(kw(p0));
  170. // }
  171. //
  172. // template <typename T0, ..., typename T ## N>
  173. // ret name(
  174. // T0 && p0, ..., TN && p ## N
  175. // , typename parameters::match<T0, ..., T ## N>::type kw = parameters()
  176. // )
  177. // {
  178. // return name ## _with_named_params(kw(p0, ..., p ## N));
  179. // }
  180. //
  181. // template <typename Params>
  182. // ret name ## _with_named_params(Params const&)
  183. //
  184. // lo and hi determine the min and max arities of the generated functions.
  185. #define BOOST_PARAMETER_MEMFUN(ret, name, lo, hi, parameters) \
  186. BOOST_PP_REPEAT_FROM_TO( \
  187. lo, BOOST_PP_INC(hi), BOOST_PARAMETER_FUN_DECL \
  188. , (ret, name, parameters) \
  189. ) \
  190. template <typename Params> \
  191. ret BOOST_PP_CAT(name, _with_named_params)(Params const& p)
  192. /**/
  193. #define BOOST_PARAMETER_FUN(ret, name, lo, hi, parameters) \
  194. template <typename Params> \
  195. ret BOOST_PP_CAT(name, _with_named_params)(Params const& p); \
  196. BOOST_PARAMETER_MEMFUN(ret, name, lo, hi, parameters)
  197. /**/
  198. #endif // include guard