Boost logo

Boost :

From: Jaakko (jajarvi_at_[hidden])
Date: 2004-04-30 18:10:02


Hi,

Brian replied to this already, and pointed out that what you want is
the result_of template.
That's not yet part of BLL. There's a similar mechanism though (sig
template) that is explained
in section 5.3.4.

Note that just the std result_type typedef is not an adequate mechanism
for expressing the
return type of a lambda functor (which is polymorphic). See below...

> Perhaps it's just me being inattentive or Boost.Lambda lacks some
> feature I would consider quite useful. Rummaging through documentation
> and source code did not turn out to be constructive.
>
> Well, the problem is:
>
> struct foo
> {
> template<typename ExprT>
> typename ExprT::result_type operator[](ExprT expr)
> {
> return expr(/*params here*/);
> }
> };
>

If ExprT is a lambda functor, say -_1, the return type
is not detemined by ExprT alone, but rather by ExprT and
the type of the argument with which the lambda functor is called.

float f; int i;
(-_1)(f) // returns float
(-_1)(i) // returns int

   Jaakko

> Umm... We can write as follows then:
>
> foo bar;
>
> bar[
> some_stl_conformant_unary_functor() // or binary, or whatever...
> compiles OK
> ];
>
> It would be nice to write little lambda expressions too,
> bar[
> std::cout << _1 // Fails miserably
> ];
> for example.
>
> The problem is that lambda expressions do not have result_type defined
> although technically they are functors too (like STL functors). It
> would be trivial to write little metafunction wrapper though. After
> all, boost::lambda::is_lambda_functor metafunction exists but I
> haven't found lambda_result_type traits or something like that.
> Documentation conveniently skips through that part of implementation
> and code is a bit obscure at times.
>
> Is there a way to implement such a metafunction
>
> boost::lambda::functor_result<T>::type that it would return result
> type of lambda expression if T is lambda
> expression or T::result_type if T is ordinary STL functor, or just
> null_type if neither of them?
>
> that its implementation would not turn out to be a pain in the...
> emm... neck? Or perhaps this could be a part of Boost.Lambda library?
>
> Regards,
> Justinas V.D.
>
> _______________________________________________
> 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