PageRenderTime 21ms CodeModel.GetById 12ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/phoenix/example/define_expression.cpp

http://hadesmem.googlecode.com/
C++ | 60 lines | 35 code | 15 blank | 10 comment | 0 complexity | 94027a78f4d83c34e026c7edf8451e15 MD5 | raw file
 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
11namespace phoenix = boost::phoenix;
12namespace proto   = boost::proto;
13
14
15// define the expression
16namespace 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
25namespace 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
40template <typename Lhs, typename Rhs>
41typename expression::plus<Lhs, Rhs>::type
42plus(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
50int 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