Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2001-11-20 09:22:21


----- Original Message -----
From: <nbecker_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Tuesday, November 20, 2001 9:08 AM
Subject: [boost] Complex-Real iterator adaptors (again)

> Since iterator_adaptors has been improved, now I can implement
> complex->real iterator adaptors. Thanks!
>
> Very useful things you can do:
>
> 1) convert a complex stream to a scalar stream, where the scalar picks
> up real and imag parts alternately. This requires the adaptor to
> hold state.
>
> 2) pick off just the real (or just imag) part of a complex stream.
> This is implemented easily just using transform_iterator.
>
> Things I don't know how to do (yet):
>
> 1) Combined two scalar streams into a complex. This is like an
> iterator adaptor, but with two inputs.

You can do this by making your Base type a std::pair<iterator1, iterator2>.
Better yet, use a tuple of iterators and write your policies so that all of
the underlying iterators are moved, etc. in parallel.

I would make a specialized iterator_adaptor called zip_iterator_adaptor
which takes a tuple of iterators as the base type, a function object (stored
in the Policies) which converts instances of the tuple type to the
value_type of the iterator. zip_iterator would store its values internally
(c.f. counting_iterator), unless the category was going to be
input_iterator_tag, in which case it could build them on-the-fly.

Regards,
Dave


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk