define_operator.hpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*==============================================================================
  2. Copyright (c) 2005-2010 Joel de Guzman
  3. Copyright (c) 2010 Thomas Heller
  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. #ifndef BOOST_PHOENIX_DEFINE_OPERATOR_HPP
  8. #define BOOST_PHOENIX_DEFINE_OPERATOR_HPP
  9. #include <boost/phoenix/core/meta_grammar.hpp>
  10. #include <boost/preprocessor/seq/for_each.hpp>
  11. #define BOOST_PHOENIX_UNARY_EXPRESSION(__, ___, name) \
  12. template <typename Operand> \
  13. struct name \
  14. : expr<proto::tag::name, Operand> \
  15. {}; \
  16. /**/
  17. #define BOOST_PHOENIX_UNARY_RULE(__, ___, name) \
  18. struct name \
  19. : expression::name<meta_grammar> \
  20. {}; \
  21. /**/
  22. #define BOOST_PHOENIX_UNARY_FUNCTIONAL(__, ___, name) \
  23. namespace functional \
  24. { \
  25. typedef \
  26. proto::functional::make_expr<proto::tag::name> \
  27. BOOST_PP_CAT(make_, name); \
  28. } \
  29. namespace result_of \
  30. { \
  31. template <typename Operand> \
  32. struct BOOST_PP_CAT(make_, name) \
  33. : boost::result_of< \
  34. functional:: BOOST_PP_CAT(make_, name)( \
  35. Operand \
  36. ) \
  37. > \
  38. {}; \
  39. } \
  40. template <typename Operand> \
  41. inline \
  42. typename result_of::BOOST_PP_CAT(make_, name)<Operand>::type \
  43. BOOST_PP_CAT(make_, name)(Operand const & operand) \
  44. { \
  45. return functional::BOOST_PP_CAT(make_, name)()(operand); \
  46. } \
  47. /**/
  48. #define BOOST_PHOENIX_BINARY_EXPRESSION(__, ___, name) \
  49. template <typename Lhs, typename Rhs> \
  50. struct name \
  51. : expr<proto::tag::name, Lhs, Rhs> \
  52. {}; \
  53. /**/
  54. #define BOOST_PHOENIX_BINARY_RULE(__, ___, name) \
  55. struct name \
  56. : expression::name<meta_grammar, meta_grammar> \
  57. {}; \
  58. /**/
  59. #define BOOST_PHOENIX_BINARY_FUNCTIONAL(__, ___, name) \
  60. namespace functional \
  61. { \
  62. typedef \
  63. proto::functional::make_expr<proto::tag::name> \
  64. BOOST_PP_CAT(make_, name); \
  65. } \
  66. namespace result_of \
  67. { \
  68. template <typename Lhs, typename Rhs> \
  69. struct BOOST_PP_CAT(make_, name) \
  70. : boost::result_of< \
  71. functional:: BOOST_PP_CAT(make_, name)( \
  72. Lhs, Rhs \
  73. ) \
  74. > \
  75. {}; \
  76. } \
  77. template <typename Rhs, typename Lhs> \
  78. inline \
  79. typename result_of::BOOST_PP_CAT(make_, name)<Rhs, Lhs>::type \
  80. BOOST_PP_CAT(make_, name)(Lhs const & lhs, Rhs const & rhs) \
  81. { \
  82. return functional::BOOST_PP_CAT(make_, name)()(lhs, rhs); \
  83. } \
  84. /**/
  85. #define BOOST_PHOENIX_GRAMMAR(_, __, name) \
  86. template <typename Dummy> \
  87. struct meta_grammar::case_<proto::tag::name, Dummy> \
  88. : enable_rule<rule::name, Dummy> \
  89. {}; \
  90. /**/
  91. #define BOOST_PHOENIX_UNARY_OPERATORS(ops) \
  92. namespace expression { \
  93. BOOST_PP_SEQ_FOR_EACH(BOOST_PHOENIX_UNARY_EXPRESSION, _, ops) \
  94. } \
  95. namespace rule { \
  96. BOOST_PP_SEQ_FOR_EACH(BOOST_PHOENIX_UNARY_RULE, _, ops) \
  97. } \
  98. BOOST_PP_SEQ_FOR_EACH(BOOST_PHOENIX_GRAMMAR, _, ops) \
  99. BOOST_PP_SEQ_FOR_EACH(BOOST_PHOENIX_UNARY_FUNCTIONAL, _, ops) \
  100. /**/
  101. #define BOOST_PHOENIX_BINARY_OPERATORS(ops) \
  102. namespace expression { \
  103. BOOST_PP_SEQ_FOR_EACH(BOOST_PHOENIX_BINARY_EXPRESSION, _, ops) \
  104. } \
  105. namespace rule { \
  106. BOOST_PP_SEQ_FOR_EACH(BOOST_PHOENIX_BINARY_RULE, _, ops) \
  107. } \
  108. BOOST_PP_SEQ_FOR_EACH(BOOST_PHOENIX_GRAMMAR, _, ops) \
  109. BOOST_PP_SEQ_FOR_EACH(BOOST_PHOENIX_BINARY_FUNCTIONAL, _, ops) \
  110. /**/
  111. #endif