From: François Duranleau (duranlef_at_[hidden])
Date: 2007-10-05 15:52:11
Why boost::function_output_iterator has no accessor to the wrapped
In STL, algorithms using an output iterator or a function/functor usually
return the iterator or function/functor received in parameter (e.g.
std::copy, std::for_each) because they are passed by copy. Then if I use a
boost::function_output_iterator, I can get a copy of that iterator in
return, but then there is no way to extract the function/functor.
Example: I have a set of points stored in a structure for range query
(e.g. a kd-tree). There is a member function to get all points falling
inside a given area and it produces its output in an output iterator. Now,
suppose I only want to do some computation on those points for which I
would actually don't need to store them all, e.g. an average of some kind.
I could do the computation on the fly using a
boost::function_output_iterator with a functor that accumulates the sum
and the number of points and at the end, I would do the division. Alas, I
can't unless the functor only keeps reference. I can't do it the classical
way I could with std::for_each because I can't access the functor with
So, long story just to try to show that it would be useful, or is there
some other considerations I didn't see that makes it a bad idea?
-- Francois Duranleau
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk