[iterator] - does there exist an opposite of Function Output Iterator?

http://www.boost.org/doc/libs/1_37_0/libs/iterator/doc/function_output_itera... Shows a unary function being adapted as an OutputIterator. Does Boost have something that does the opposite, i.e. takes an OutputIterator and adapts it as a unary function object? In my own code I currently have: template <typename OutputIterator> struct output_iterator_function { explicit output_iterator_function(OutputIterator i) : iter(i) { } template <typename T> void operator()(const T &v) { *iter++ = v; } OutputIterator iter; }; template <typename OutputIterator> output_iterator_function<OutputIterator> make_output_iterator_function(OutputIterator i) { return output_iterator_function<OutputIterator>(i); } If this doesn't already exist in Boost.Iterator, it seems like it would nicely complement the already existing function_output_iterator. --Michael Fawcett

AMDG Michael Fawcett wrote:
http://www.boost.org/doc/libs/1_37_0/libs/iterator/doc/function_output_itera...
Shows a unary function being adapted as an OutputIterator. Does Boost have something that does the opposite, i.e. takes an OutputIterator and adapts it as a unary function object?
In my own code I currently have:
<snip>
using namespace boost::lambda; *var(i)++ = _1; ? In Christ, Steven Watanabe

On Thu, Feb 5, 2009 at 12:33 PM, Steven Watanabe <watanabesj@gmail.com> wrote:
Michael Fawcett wrote:
http://www.boost.org/doc/libs/1_37_0/libs/iterator/doc/function_output_itera...
Shows a unary function being adapted as an OutputIterator. Does Boost have something that does the opposite, i.e. takes an OutputIterator and adapts it as a unary function object?
using namespace boost::lambda; *var(i)++ = _1;
Thanks, as always, Steven. While clever, Boost.Lamba seems like overkill for this extremely simple task. Is it your experience that it would generate code as efficient as what I originally posted? Do you feel that such functionality doesn't belong in Boost.Iterator? I think it nicely complements function_output_iterator. --Michael Fawcett

on Thu Feb 05 2009, Michael Fawcett <michael.fawcett-AT-gmail.com> wrote:
Thanks, as always, Steven.
While clever, Boost.Lamba seems like overkill for this extremely simple task. Is it your experience that it would generate code as efficient as what I originally posted?
Should be easily as efficient.
Do you feel that such functionality doesn't belong in Boost.Iterator?
I definitely think it doesn't. Boost.Iterator is about constructing iterators. You're constructing a function. Boost.Lambda or Bind or Pheonix are the right tools for that job.
I think it nicely complements function_output_iterator.
Then maybe function_output_iterator ought to be moved into the lambda lib ;-) -- Dave Abrahams BoostPro Computing http://www.boostpro.com

On Thu, Feb 5, 2009 at 10:47 PM, David Abrahams <dave@boostpro.com> wrote:
on Thu Feb 05 2009, Michael Fawcett <michael.fawcett-AT-gmail.com> wrote:
Do you feel that such functionality doesn't belong in Boost.Iterator?
I definitely think it doesn't. Boost.Iterator is about constructing iterators. You're constructing a function. Boost.Lambda or Bind or Pheonix are the right tools for that job.
Right, it doesn't belong in Boost.Iterator.
I think it nicely complements function_output_iterator.
Then maybe function_output_iterator ought to be moved into the lambda lib ;-)
I only meant it seemed nice to have the converse available in the same form, not as a lamba construct. I'll stick with my little solution for now. --Michael Fawcett
participants (3)
-
David Abrahams
-
Michael Fawcett
-
Steven Watanabe