
Maurizio Vitale wrote:
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...
I'm flattered!
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.
Right, so when you inherit from callable_context, it unpacks the expression and sends it to your operator(). You can't get at the expression object or its type before it was unpacked. If you need that, then callable_context isn't right for you. Just to clarify what I said earlier, a binary plus node would get passed to your context like: struct my_context : callable_context<my_context> { // ... template<class Left, class Right> some-type operator()(tag::plus, Left const& l, Right const& r) { return something; } }; my_context is "callable" in that it must satisfy the result_of protocol. So it must either have a result_type typedef, or a nested result<> class template. So, you could partially specialize the result<> template to calculate the return type of plus operations like: template<class Sig> struct result; template<class This, class Left, class Right> struct result<This(tag::plus, Left const &, Right const &)> { typedef some-type type; }; HTH, -- Eric Niebler Boost Consulting www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com