Blitz logo

Blitz Support :

From: Xianlian Zhou (alex.xl.zhou_at_[hidden])
Date: 2005-05-22 17:51:14


Hi,

I have recently encounted a problem with the postfix++ of the
ArrayIterator. And I got several puzzles here, please forgive my
ignorance at first.

In the new version of blitz, the ArrayIterator has been modified to
be more STL compliant such that the postfix operator++ now returns a
const reference to the iterator object as it was before the
increment(as in CVS).

However, my code below doesn't work..
=============================================
        Array<double,1> BV(3);
        BV=1;
        Array<double,1>::iterator it=BV.begin();
        cout<<*it++<<endl; //crash here, it++ returns nothing;
=============================================

I checked the code in iter.h as:
=============================================
    const ArrayIterator<T,N>& operator++(int)
    {
        ArrayIterator<T,N> tmp = *this;
        ++(*this);
        return tmp;
    }
=============================================
Can we return a local object to a const reference?

My another question is, why here the const reference is used? Isn't
the ArrayIterator used as non-const iterator in array-impl.h?

Thanks for reply.

Alex