transform_iterator and lambda functors

Hello, I am trying to use transform_iterator with a lambda functor, but the compiler complains that the lambda functor does not contain a type called 'result_type', which the transform_iterator requires. I would have expected lambda functors to have this type. Any ideas on why it doesn't? Here is the code line causing the problem: return make_transform_iterator(attributes.begin(), bind(&pair<const AttributeType, string>::second, _1)); where attributes is of type map<AttributeType, string>. Here is the error message: /usr/local/include/boost-1_32/boost/iterator/transform_iterator.hpp:43: no type named `result_type' in `class boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<2, boost::lambda::function_action<2, boost::lambda::detail::unspecified>
, boost::tuples::tuple<std::string std::pair<const AttributeType, std::string>::*, const boost::lambda::lambda_functor<boost::lambda::placeholder<1> >, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> > >'
Thanks, Rodrigo

Rodrigo de Salvo Braz <braz@uiuc.edu> writes:
Hello,
I am trying to use transform_iterator with a lambda functor, but the compiler complains that the lambda functor does not contain a type called 'result_type', which the transform_iterator requires.
I would have expected lambda functors to have this type. Any ideas on why it doesn't?
Because often the result type depends on the argument type that is actually passed: (_1 + 3)(4) vs. (_1 + 3)(static_cast<char const*>("hello")) HTH, -- Dave Abrahams Boost Consulting http://www.boost-consulting.com

On Mon, 22 Nov 2004, David Abrahams wrote:
Because often the result type depends on the argument type that is actually passed:
(_1 + 3)(4)
vs.
(_1 + 3)(static_cast<char const*>("hello"))
But isn't it the case that any instantiated functor object will have a well-defined result_type? In your examples it seems '(_1 + 3)' would be instantiated to different types. Anyway, I guess a better solution to my particular problem would be for make_transform_iterator to be able to receive a result type and make an adaptable functor out of any UnaryFunction, right? Thanks, Rodrigo

Rodrigo de Salvo Braz <braz@uiuc.edu> writes:
On Mon, 22 Nov 2004, David Abrahams wrote:
Because often the result type depends on the argument type that is actually passed:
(_1 + 3)(4)
vs.
(_1 + 3)(static_cast<char const*>("hello"))
But isn't it the case that any instantiated functor object will have a well-defined result_type? In your examples it seems '(_1 + 3)' would be instantiated to different types.
The expression _1 + 3 is a function object by itself, and that's what you pass to the algorithm.
Anyway, I guess a better solution to my particular problem would be for make_transform_iterator to be able to receive a result type and make an adaptable functor out of any UnaryFunction, right?
Yes. Patches welcome. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com

Frank Birbacher <bloodymir.crap@gmx.net> writes:
Hi!
David Abrahams wrote:
Because often the result type depends on the argument type that is actually passed:
But he is binding a pointer-to-member-variable which definately has a result type (which is the type of the member).
For the reasons that they didn't make that particular result into an adaptable unary function, you have to consult the Boost.Lambda authors. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com
participants (3)
-
David Abrahams
-
Frank Birbacher
-
Rodrigo de Salvo Braz