macros.hpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Copyright David Abrahams, Daniel Wallin 2003. Use, modification and
  2. // distribution is subject to the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_PARAMETER_MACROS_050412_HPP
  6. #define BOOST_PARAMETER_MACROS_050412_HPP
  7. #include <boost/preprocessor/tuple/elem.hpp>
  8. #include <boost/preprocessor/repetition/repeat_from_to.hpp>
  9. #include <boost/preprocessor/arithmetic/inc.hpp>
  10. #include <boost/preprocessor/logical/bool.hpp>
  11. #include <boost/preprocessor/punctuation/comma_if.hpp>
  12. #include <boost/preprocessor/control/expr_if.hpp>
  13. #include <boost/preprocessor/repetition/enum_params.hpp>
  14. #include <boost/preprocessor/repetition/enum_binary_params.hpp>
  15. #include <boost/preprocessor/cat.hpp>
  16. #include <boost/detail/workaround.hpp>
  17. #define BOOST_PARAMETER_FUN_TEMPLATE_HEAD1(n) \
  18. template<BOOST_PP_ENUM_PARAMS(n, class T)>
  19. #define BOOST_PARAMETER_FUN_TEMPLATE_HEAD0(n)
  20. #if ! defined(BOOST_NO_SFINAE) && ! BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x592))
  21. # define BOOST_PARAMETER_MATCH_TYPE(n, param) \
  22. BOOST_PP_EXPR_IF(n, typename) param::match \
  23. < \
  24. BOOST_PP_ENUM_PARAMS(n, T) \
  25. >::type
  26. #else
  27. # define BOOST_PARAMETER_MATCH_TYPE(n, param) param
  28. #endif
  29. #define BOOST_PARAMETER_FUN_DECL(z, n, params) \
  30. \
  31. BOOST_PP_CAT(BOOST_PARAMETER_FUN_TEMPLATE_HEAD, BOOST_PP_BOOL(n))(n) \
  32. \
  33. BOOST_PP_TUPLE_ELEM(3, 0, params) \
  34. BOOST_PP_TUPLE_ELEM(3, 1, params)( \
  35. BOOST_PP_ENUM_BINARY_PARAMS(n, T, const& p) \
  36. BOOST_PP_COMMA_IF(n) \
  37. BOOST_PARAMETER_MATCH_TYPE(n,BOOST_PP_TUPLE_ELEM(3, 2, params)) \
  38. kw = BOOST_PP_TUPLE_ELEM(3, 2, params)() \
  39. ) \
  40. { \
  41. return BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(3, 1, params), _with_named_params)( \
  42. kw(BOOST_PP_ENUM_PARAMS(n, p)) \
  43. ); \
  44. }
  45. // Generates:
  46. //
  47. // template<class Params>
  48. // ret name ## _with_named_params(Params const&);
  49. //
  50. // template<class T0>
  51. // ret name(T0 const& p0, typename parameters::match<T0>::type kw = parameters())
  52. // {
  53. // return name ## _with_named_params(kw(p0));
  54. // }
  55. //
  56. // template<class T0, ..., class TN>
  57. // ret name(T0 const& p0, ..., TN const& PN
  58. // , typename parameters::match<T0, ..., TN>::type kw = parameters())
  59. // {
  60. // return name ## _with_named_params(kw(p0, ..., pN));
  61. // }
  62. //
  63. // template<class Params>
  64. // ret name ## _with_named_params(Params const&)
  65. //
  66. // lo and hi determines the min and max arity of the generated functions.
  67. #define BOOST_PARAMETER_FUN(ret, name, lo, hi, parameters) \
  68. \
  69. template<class Params> \
  70. ret BOOST_PP_CAT(name, _with_named_params)(Params const& p); \
  71. \
  72. BOOST_PP_REPEAT_FROM_TO( \
  73. lo, BOOST_PP_INC(hi), BOOST_PARAMETER_FUN_DECL, (ret, name, parameters)) \
  74. \
  75. template<class Params> \
  76. ret BOOST_PP_CAT(name, _with_named_params)(Params const& p)
  77. #define BOOST_PARAMETER_MEMFUN(ret, name, lo, hi, parameters) \
  78. \
  79. BOOST_PP_REPEAT_FROM_TO( \
  80. lo, BOOST_PP_INC(hi), BOOST_PARAMETER_FUN_DECL, (ret, name, parameters)) \
  81. \
  82. template<class Params> \
  83. ret BOOST_PP_CAT(name, _with_named_params)(Params const& p)
  84. #endif // BOOST_PARAMETER_MACROS_050412_HPP