|
Boost : |
From: Eric Niebler (eric_at_[hidden])
Date: 2007-06-01 10:36:29
Larry Evans wrote:
> Hi Eric,
>
> I need a context with something like the following methods:
>
> template< typename Tag, typename Left, typename Right >
> result_type operator()(expr<Tag, Left, Right> const &expr) const
> {
> std::cout<<std::setw(indent)
> <<""<<"binary_expr:"<<expr.get_instance()<<"\n";
> indent+=2;
> proto::eval(left, *this);
> proto::eval(right, *this);
> indent-=2;
> }
>
> where the expression tree node argument remains "packaged":
>
> (expr<Tag, Left, Right> const &expr)
>
> in contrast to the unpacked version:
>
> (Tag, Left const &left, Right const &right)
Sure. Only context types derived from callable_context get unpacked
nodes like that. If you don't inherit from callable_context, you'll get
the whole node without any modification. The interface is a bit
different, though. You'll need something like:
struct my_context
{
template<typename Expr>
struct eval
{
typedef ... result_type;
result_type
operator()(Expr &expr, my_context &ctx) const
{
return ...;
}
};
};
If you want to handle binary nodes specially, you would define the eval
member template as:
template<typename Expr, long Arity = Expr::arity::value>
struct eval
and then partially specialize for binary nodes:
template<typename Expr>
struct eval<Expr, 2>
HTH,
-- Eric Niebler Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk