Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-06-10 07:49:02

"Maxim Yegorushkin" <e-maxim_at_[hidden]> writes:

> Is there a way to make a boost::lambda functor adaptable, that is to make it define result_type? There is a ret<> function template that lets one specify the result type, but the returned functor still does not have result_type typedef.
> I've encountered the problem trying to use boost::transform_iterator with a boost::lambda functor:
> std::vector<int> intVect;
> boost::make_transform_iterator(intVect.begin(), boost::lambda::_1 / 2);
> transform_iterator<> does not compile comlaining the functor does not have result_type.
> As a workaround I had to write something like:
> template<class R, class T>
> struct result_type_wrapper : T
> {
> typedef R result_type;
> result_type_wrapper(T const& t) : T(t) {}
> };
> template<class R, class T>
> inline
> result_type_wrapper<R, T> result_type(T const& t) { return t; }
> boost::make_transform_iterator(intVect.begin(), result_type<int>(boost::lambda::_1 / 2));
> Am I missing something? Is there a way to avoid using result_type_wrapper<>?

You could use boost::make_adaptable from
boost/bind/make_adaptable.hpp, but there really ought to be a version
of make_transform_iterator that does that for you.

Dave Abrahams
Boost Consulting

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