1 /*==============================================================================
2 Copyright (c) 2005-2010 Joel de Guzman
3 Copyright (c) 2011 Thomas Heller
4
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 ==============================================================================*/
8
9 #include <boost/phoenix/core.hpp>
10
11 namespace phoenix = boost::phoenix;
12 namespace proto = boost::proto;
13
14
15 // define the expression
16 namespace expression
17 {
18 template <typename Lhs, typename Rhs>
19 struct plus
20 : phoenix::expr<proto::tag::plus, Lhs, Rhs>
21 {};
22 }
23
24 // extend the grammar, to recognice the expression
25 namespace boost { namespace phoenix {
26
27 template <>
28 struct meta_grammar::case_<proto::tag::plus>
29 : enable_rule<
30 ::expression::plus<
31 meta_grammar
32 , meta_grammar
33 >
34 >
35 {};
36
37 }}
38
39 // build a generator
40 template <typename Lhs, typename Rhs>
41 typename expression::plus<Lhs, Rhs>::type
plus(Lhs const & lhs,Rhs const & rhs)42 plus(Lhs const & lhs, Rhs const & rhs)
43 {
44 return expression::plus<Lhs, Rhs>::make(lhs, rhs);
45 }
46
47 #include <boost/proto/proto.hpp>
48 #include <iostream>
49
main()50 int main()
51 {
52
53 plus(6, 5);
54
55 proto::display_expr(plus(6, 5));
56
57 std::cout << plus(5, 6)() << "\n";
58 }
59
60
61