#include <boost/proto/proto.hpp>
#include <boost/mpl/int.hpp>
#include <boost/fusion/container/vector.hpp>
#include <boost/fusion/container/generation/make_vector.hpp>
namespace mpl = boost::mpl;
namespace proto = boost::proto;
namespace fusion = boost::fusion;
template<typename I> struct placeholder : I {};
struct identity : proto::callable
{
typedef int result_type;
int operator()(int a) const
{
return a;
}
};
struct identity_ {};
struct IdentityGrammar
: proto::or_<
proto::when<
proto::terminal<placeholder<proto::_>>
, proto::functional::at(proto::_state, proto::_value)
>
, proto::when<proto::terminal<identity_>, proto::_void>
, proto::when<
proto::function<IdentityGrammar, proto::terminal<proto::_>>
, proto::and_<
IdentityGrammar(proto::_child1)
, identity(proto::_value(proto::_child1))
>
>
>
{};
template<typename Expr>
struct identity_expr;
struct identity_domain
: proto::domain<proto::pod_generator<identity_expr>, IdentityGrammar>
{};
template<typename Expr>
struct identity_expr
{
BOOST_PROTO_EXTENDS(Expr, identity_expr<Expr>, identity_domain)
};
identity_expr<proto::terminal<identity_>::type> const identity = {{}};
identity_expr<proto::terminal<placeholder<mpl::int_<0> > >::type> _1;
int main()
{
auto expr = identity(_1);
proto::display_expr(expr);
int result = IdentityGrammar()(expr,fusion::make_vector(3));
std::cout << "result=" << result << " [ expect 3 ]" << std::endl;
return 0;
}