![]() |
Blitz Support : |
From: Julian Cummings (cummings_at_[hidden])
Date: 2005-05-23 14:38:56
Hello Alex,
I tested your example code under gcc 4.0.0 and it works properly for me (no
crash), although it does issue a warning about returning a reference to a
local temporary in the iter.h code. I thought that returning a const
reference in this case (as the blitz code currently does) is an OK thing to
do. However, I looked at the gcc <iterator> code, and they return the
iterator by value in the case of the postfix operator++. I'm not sure what
the original motivation for returning a const reference was in this
situation, but perhaps I need to change this and return by value as the gcc
<iterator> code is doing. Comments anyone?
Regards, Julian C.
Dr. Julian C. Cummings
Staff Scientist, CACR/Caltech
(626) 395-2543
cummings_at_[hidden]
> -----Original Message-----
> From: blitz-support-bounces_at_[hidden]
> [mailto:blitz-support-bounces_at_[hidden]] On Behalf Of
> Xianlian Zhou
> Sent: Sunday, May 22, 2005 3:51 PM
> To: Support list for Blitz++
> Subject: [Blitz-support] postfix++ for the ArrayIterator
>
> 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
>
> _______________________________________________
> Blitz-support mailing list
> Blitz-support_at_[hidden]
> http://www.oonumerics.org/mailman/listinfo.cgi/blitz-support
>
>