Boost logo

Boost :

From: Maurizio Vitale (maurizio.vitale_at_[hidden])
Date: 2007-08-20 10:39:30


Eric, just for my understanding, your suggestion is also the only way
to proceed when the result type depends on Expr, right?
Thanks,

        Maurizio

On Jun 1, 2007, at 10:36 AM, Eric Niebler wrote:

> 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
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/
> listinfo.cgi/boost
>
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk