On Sun, 2011-05-29 at 09:55 +0200, Anders Gidenstam wrote:
> On Sat, 28 May 2011, Geoff McLane wrote:
>
> > Hi all,
> >
> > I read (everywhere) that a vector erase invalidates
> > all current iterators - see say -
> > http://www.cplusplus.com/reference/stl/vector/erase/
> > so I really do not understand why genfans.cxx has lasted
> > so long like it is ;=((
> >
> > When it does a -
> > tris.erase( t_current );
> > it should reset the iterators. The small patch attached
> > does just that...
> >
> > Maybe somehow, on some platforms, the iterators are
> > 'correctly' adjusted, but certainly NOT in WIN32, and I
> > suspect the same in other platforms!
> >
> > I would respectfully request the attached patch be
> > applied soonest, unless there is some other reasoning
> > at play here.
> >
> > It certainly works better for me ;=)) And removes
> > another reason why fgfs-construct can abort
> > without apparent reason!
>
> Hi Geoff,
>
> If I recall correctly (it is still before my morning coffee here :)
> vector::erase() returns a new iterator that you can use to continue the
> iteration, so the below should work for continuing the iteration:
>
> t_current = tris.erase( t_current );
> t_last = tris.end();
>
> However, if you have more iterators around (than t_current and t_last)
> that will need to be adjusted perhaps a full restart is warranted.
>
> Cheers,
>
> Anders
Hi Anders,
Thanks for the information... and before your
coffee as well ;=))
If erase does returns a 'next' valid iterator
after the erased item, then a slightly 'faster'
patch would indeed be, as you indicate :-
---
src/Lib/Optimize/genfans.cxx | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/src/Lib/Optimize/genfans.cxx b/src/Lib/Optimize/genfans.cxx
index 166c354..9551088 100644
--- a/src/Lib/Optimize/genfans.cxx
+++ b/src/Lib/Optimize/genfans.cxx
@@ -225,7 +225,8 @@ opt_list TGGenFans::greedy_build( triele_list tris )
{
// << t_current->get_n3()
// << " from master tri pool"
// << endl;
- tris.erase( t_current );
+ t_current = tris.erase( t_current );
+ t_last = tris.end();
} else {
++t_current;
}
--
1.7.0.4
since in that particular loop t_current and t_last
are the only iterators used... it compiles ok
like that, but yet to 'test' this change...
But also in this case, a full restart of the loop
would not 'cost' much more... just to be very sure...
Just hope one of the 'fixes' gets into mapserver
terragear cs soon ;=)) adding a little more
stability to the likes of fgfs-construct, as one
exe which uses this library...
Regards,
Geoff.
------------------------------------------------------------------------------
vRanger cuts backup time in half-while increasing security.
With the market-leading solution for virtual backup and recovery,
you get blazing-fast, flexible, and affordable data protection.
Download your free trial now.
http://p.sf.net/sfu/quest-d2dcopy1
_______________________________________________
Flightgear-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/flightgear-devel