1 /*==============================================================================
2 Copyright (c) 2005-2010 Joel de Guzman
3 Copyright (c) 2010 Thomas Heller
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 ==============================================================================*/
9 #ifndef BOOST_PHOENIX_DEFINE_OPERATOR_HPP
10 #define BOOST_PHOENIX_DEFINE_OPERATOR_HPP
12 #include <boost/phoenix/core/meta_grammar.hpp>
13 #include <boost/preprocessor/seq/for_each.hpp>
15 #define BOOST_PHOENIX_UNARY_EXPRESSION(__, ___, name) \
16 template <typename Operand> \
18 : expr<proto::tag::name, Operand> \
22 #define BOOST_PHOENIX_UNARY_RULE(__, ___, name) \
24 : expression::name<meta_grammar> \
28 #define BOOST_PHOENIX_UNARY_FUNCTIONAL(__, ___, name) \
29 namespace functional \
32 proto::functional::make_expr<proto::tag::name> \
33 BOOST_PP_CAT(make_, name); \
37 template <typename Operand> \
38 struct BOOST_PP_CAT(make_, name) \
40 functional:: BOOST_PP_CAT(make_, name)( \
46 template <typename Operand> \
48 typename result_of::BOOST_PP_CAT(make_, name)<Operand>::type \
49 BOOST_PP_CAT(make_, name)(Operand const & operand) \
51 return functional::BOOST_PP_CAT(make_, name)()(operand); \
55 #define BOOST_PHOENIX_BINARY_EXPRESSION(__, ___, name) \
56 template <typename Lhs, typename Rhs> \
58 : expr<proto::tag::name, Lhs, Rhs> \
62 #define BOOST_PHOENIX_BINARY_RULE(__, ___, name) \
64 : expression::name<meta_grammar, meta_grammar> \
68 #define BOOST_PHOENIX_BINARY_FUNCTIONAL(__, ___, name) \
69 namespace functional \
72 proto::functional::make_expr<proto::tag::name> \
73 BOOST_PP_CAT(make_, name); \
77 template <typename Lhs, typename Rhs> \
78 struct BOOST_PP_CAT(make_, name) \
80 functional:: BOOST_PP_CAT(make_, name)( \
86 template <typename Rhs, typename Lhs> \
88 typename result_of::BOOST_PP_CAT(make_, name)<Rhs, Lhs>::type \
89 BOOST_PP_CAT(make_, name)(Lhs const & lhs, Rhs const & rhs) \
91 return functional::BOOST_PP_CAT(make_, name)()(lhs, rhs); \
95 #define BOOST_PHOENIX_GRAMMAR(_, __, name) \
96 template <typename Dummy> \
97 struct meta_grammar::case_<proto::tag::name, Dummy> \
98 : enable_rule<rule::name, Dummy> \
102 #define BOOST_PHOENIX_UNARY_OPERATORS(ops) \
103 namespace expression { \
104 BOOST_PP_SEQ_FOR_EACH(BOOST_PHOENIX_UNARY_EXPRESSION, _, ops) \
107 BOOST_PP_SEQ_FOR_EACH(BOOST_PHOENIX_UNARY_RULE, _, ops) \
109 BOOST_PP_SEQ_FOR_EACH(BOOST_PHOENIX_GRAMMAR, _, ops) \
110 BOOST_PP_SEQ_FOR_EACH(BOOST_PHOENIX_UNARY_FUNCTIONAL, _, ops) \
114 #define BOOST_PHOENIX_BINARY_OPERATORS(ops) \
115 namespace expression { \
116 BOOST_PP_SEQ_FOR_EACH(BOOST_PHOENIX_BINARY_EXPRESSION, _, ops) \
119 BOOST_PP_SEQ_FOR_EACH(BOOST_PHOENIX_BINARY_RULE, _, ops) \
121 BOOST_PP_SEQ_FOR_EACH(BOOST_PHOENIX_GRAMMAR, _, ops) \
122 BOOST_PP_SEQ_FOR_EACH(BOOST_PHOENIX_BINARY_FUNCTIONAL, _, ops) \