Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-09-03 08:17:42


Dan Eloff <dan.eloff_at_[hidden]> writes:

>>For things like this the solution is usually to store the
>>dereferenced value inside the iterator itself. You might look into
>>using boost::optional for efficiency in this case.
>
> If I store it in the iterator I get crashes because a reference is
> floating around to the long dead temporary iterator returned from post
> increment.

Dereference can return by value. That's normal for input iterators.
But IIRC, the user of an input iterator isn't allowed to bind a
reference to or take the address of the result of dereferencing
anyway. So you might want to fix the code that does that.

> I can store it in the parent (container) class of the
> iterator ( what I do now anyway ) but I need to store two values with
> post increment.
>
>>I'm not sure there _is_ a good reason. If you'd like to patch it to
>>do it the other way, and if all of the Boost.Python regression tests
>>still pass, I'll apply your patch.
>
> If only so nobody else will have to go through what I just did today
> and yesterday I will make the patch. I'll post to the C++-sig when
> I've got it.

Please try to run the regression tests first!

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com

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