Boost logo

Boost :

From: Justinas V.D. (vygintas.daugmaudis_at_[hidden])
Date: 2004-04-29 14:05:19


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*/);

Umm... We can write as follows then:

foo bar;

    some_stl_conformant_unary_functor() // or binary, or whatever...
compiles OK

It would be nice to write little lambda expressions too,
    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?

Justinas V.D.

Boost list run by bdawes at, gregod at, cpdaniel at, john at