#include "functor.h" #include #include namespace proto = boost::proto; using proto::_; template struct PredicateExpr; struct PredicateGramma:proto::or_< proto::terminal const& >, proto::logical_or, proto::logical_and, proto::negate >{}; struct PredicateDomain: proto::domain, PredicateGramma>{}; struct PredicateContext{ int i; PredicateContext(int i_):i(i_){} template struct eval:proto::default_eval{}; template struct eval{ typedef typename bool result_type; result_type operator()(Expr & expr, PredicateContext& ctx)const{ return proto::value(expr)(ctx.i); } }; }; template struct PredicateExpr : proto::extends, PredicateDomain> { PredicateExpr( const Expr& expr = Expr()):PredicateExpr::proto_extends(expr){} bool operator()(int i) const{ PredicateContext ctx(i); return proto::eval(*this, ctx); } }; template struct Predicate:PredicateExpr const&>::type> { typedef typename proto::terminal const&>::type expr_type; Predicate():PredicateExpr(expr_type::make(T())){} template Predicate(R r):PredicateExpr(expr_type::make(T(r))){} };