Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost range iterator pointing to wrong element
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2013-09-24 00:36:27


On 9/22/2013 6:37 AM, Quoth Giorgos Sermaidis:
> struct to_include {
> bool operator()(const std::pair<bool,int>& x) {
> return x.first;
> }
> };
[...]
> /* reverse and then filter */
> auto rf = container_cpy | reversed | filtered(to_include());
> auto rf_it1 = rf.begin();
> auto rf_it2 = std::next(rf_it1);
> rf_it2->first = false;

This is just a guess, but it strikes me as potentially dodgy to retain
iterators to a filtered sequence after modifying the result of the
filter predicate on that sequence. (This seems like something that
would invalidate iterators, just like certain collection modifications do.)

Have you tried re-acquiring the iterators from "rf" or "fr" after
assigning to "first", rather than continuing to use them? (You
shouldn't need to reconstruct "rf" or "fr" themselves, just the iterators.)


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net