phoenix/example/define_expression.cpp
Thomas Heller b8592544de cleaned up doc directory
[SVN r69060]
2011-02-19 16:38:25 +00:00

61 lines
1.3 KiB
C++

/*==============================================================================
Copyright (c) 2005-2010 Joel de Guzman
Copyright (c) 2011 Thomas Heller
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#include <boost/phoenix/core.hpp>
namespace phoenix = boost::phoenix;
namespace proto = boost::proto;
// define the expression
namespace expression
{
template <typename Lhs, typename Rhs>
struct plus
: phoenix::expr<proto::tag::plus, Lhs, Rhs>
{};
}
// extend the grammar, to recognice the expression
namespace boost { namespace phoenix {
template <>
struct meta_grammar::case_<proto::tag::plus>
: enable_rule<
::expression::plus<
meta_grammar
, meta_grammar
>
>
{};
}}
// build a generator
template <typename Lhs, typename Rhs>
typename expression::plus<Lhs, Rhs>::type
plus(Lhs const & lhs, Rhs const & rhs)
{
return expression::plus<Lhs, Rhs>::make(lhs, rhs);
}
#include <boost/proto/proto.hpp>
#include <iostream>
int main()
{
plus(6, 5);
proto::display_expr(plus(6, 5));
std::cout << plus(5, 6)() << "\n";
}