Boost logo

Boost :

From: Maurizio Vitale (maurizio.vitale_at_[hidden])
Date: 2007-08-27 12:04:51


On Aug 27, 2007, at 11:54 AM, Eric Niebler wrote:

>
> (Sorry for the delay, I'm just back from a week-long vacation.)
>
Not a problem, I know all about your whereabouts from your posts.
Avid reader of yours I am...

>
> Maurizio Vitale wrote:
>> On Jun 1, 2007, at 10:36 AM, Eric Niebler wrote:
>>> 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>
>>>
>>>
>> Eric, just for my understanding, your suggestion is also the only way
>> to proceed when the result type depends on Expr, right?
>
>
> Not so. If your context type inherits from callable_context, you can
> define a nested result class template for calculating the return type.
> In this way, the return type can be made to depend on the
> expression type.
>
but you still need to explicitly pass the expression type to the
context, like this:

template<typename Expr>
struct my_context : callabla_context<my_context<Expr> > {
   typedef Functor_Of<Expr>::type result_type;
   ....
};

or am I missing a way to get to Expr in a class inheriting from
callable_context?
you cannot overload operator()() or you ruin the unpackaging done by
callable_context.

I'm using the above in my code (even though I did forget about it
when asking),
so if there was a better way I'd be glad to hear.
Regards,

        Maurizio


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