[prev in list] [next in list] [prev in thread] [next in thread] 

List:       boost-users
Subject:    Re: [Boost-users] =?utf-8?q?=5BBoost=2EIterator=5D_transform=5Fiterat?=
From:       dariomt <dariomt () gmail ! com>
Date:       2015-07-31 12:40:29
Message-ID: loom.20150731T142821-223 () post ! gmane ! org
[Download RAW message or body]

Edward Diener <eldiener <at> tropicsoft.com> writes:

> 
> On 7/30/2015 7:06 AM, dariomt <at> gmail.com wrote:
> > Here is my problem: for any given algorithm that writes its output 
into
> > an output iterator, I'd like to apply a transformation *before* 
writing
> > to the output iterator.
> >
> > e.g. inside the algorithm the output iterator is dereferenced and
> > incremented to write each result, typically like this:
> >
> > *output++ = ith_result;
> >
> > I'd like to wrap the output iterator with a unary function func such
> > that the effect is equivalent to:
> >
> > *output++ = func( ith_result );
> >
> > I'm looking at the adaptors in Boost.Iterator but I cannot find a
> > suitable one.
> >
> > Am I missing anything?
> > Is there a better approach?
> 
> Can you not use the function_output_iterator to accomplish what you 
want 
> to do ?
> 

IIUC the function_output_iterator "fakes" an output iterator with a 
function object that gets called for each element written to the 
iterator.

I need to wrap *both* an actual output iterator and a function object, 
and I need to apply the function *before* writing to the actual output 
iterator.

Given that the output iterator is written by dereference and assignment, 
I think I would need some kind of proxy reference, that when assigned to 
applies the function before doing the actual assignment.

That looks ugly, so I'm asking here for a more elegant solution :)


_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic