Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2001-11-19 09:16:32


The iterator_adaptors library supports the storing of state (put it in the
Policies class).

What you have below are not standard conforming iterators, which is one
reason to use the library

-Dave

----- Original Message -----
From: <nbecker_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Monday, November 19, 2001 8:44 AM
Subject: Re: [boost] Fast Fourier Toolbox

> Use iterators and adapt between complex and real with an iterator
> adaptor.
>
> Here's what I use:
> note: I don't think this can easily be based on boost/iterator_adaptors,
because we
> require an adaptor that has state.
>
> file://! Convert complex to interleaved scalars
> template<class T, class ComplexIterator>
> class CtoR {
> ComplexIterator I;
> int cnt;
>
> public:
> typedef T value_type;
> typedef CtoR self;
> typedef ptrdiff_t difference_type;
>
> CtoR (ComplexIterator C) :
> I (C),
> cnt (0)
> {}
>
> value_type operator*() const {
> return (cnt % 2 == 0) ? real (*I) : imag (*I);
> }
>
> self& operator++ () {
> cnt++;
> if (cnt == 2) {
> I++;
> cnt = 0;
> }
> return *this;
> }
>
> self operator++ (int) {
> self tmp = *this;
> ++*this;
> return tmp;
> }
>
> bool operator==(const self& x) const { return I == x.I && cnt ==
x.cnt; }
>
> bool operator!=(const self& x) const { return !(*this == x); }
>
> difference_type operator- (const self& x) const {
> return 2 * (I - x.I) + (cnt - x.cnt);
> }
>
> self operator+(difference_type n) const {
> self tmp = *this;
> return tmp += n;
> }
>
> self& operator+=(difference_type n) {
> I += n/2;
> cnt += n % 2;
> if (cnt == 2) {
> I++;
> cnt = 0;
> }
> return *this;
> }
> };
>
> file://! convert interleaved scalars to complex
> template<class T, class ScalarIterator>
> class RtoC {
> ScalarIterator I;
>
> public:
> typedef complex<T> value_type;
> typedef RtoC self;
> typedef ptrdiff_t difference_type;
>
> RtoC (ScalarIterator S) :
> I (S)
> {}
>
> value_type operator*() const {
> return complex<T> (*I, *(I+1));
> }
>
> self& operator++ () {
> I += 2;
> return *this;
> }
>
> self operator++ (int) {
> self tmp = *this;
> ++*this;
> return tmp;
> }
>
> bool operator==(const self& x) const { return I == x.I; }
>
> value_type operator[] (difference_type n) const { return *(*this + n); }
>
> self operator+(difference_type n) const {
> self tmp = *this;
> return tmp += n;
> }
>
> self& operator+=(difference_type n) {
> I += 2 * n;
> return *this;
> }
>
> };
>
> Info: http://www.boost.org Unsubscribe:
<mailto:boost-unsubscribe_at_[hidden]>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>


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