Boost logo

Boost Users :

Subject: Re: [Boost-users] [BGL] adjacency_iterator invalidation with adjacency_list<listS, listS, unorderedS>
From: cobalto (scott.a.merritt_at_[hidden])
Date: 2010-02-23 20:09:15


Andrew Sutton-2 wrote:
>
>> I'm wondering if the documentation is incorrect. Perhaps it is just
>> imprecise, and removing any edge from the source vertex of an
>> adjacency_iterator invalidates that iterator?
>
> That behavior should actually be correct since an adjacency iterator is
> just
> a wrapper around an out edge iterator. I haven't looked at the
> documentation
> on adjacency iterator invalidation, so it the docs may be incorrect.
>

In keeping with your comments, I have tried with both out edge iterators and
adjacency iterators in the below simplified examples. Both indeed exhibit
the same behavior, but they seem to invalidate the iterators, when
(according to the documentation) the iterators should remain valid. There
must be a good technical reason why these iterators are invalidated. If
anyone can explain that to me, I would greatly appreciate it. In any event,
if someone else can confirm this, I think the documentation should be
changed.

Two simple functions that should work but don't (see previous post for
typedefs):

void DeleteNeighborEdges_AdjIter(Vertex v, Graph& g)
{
   typedef boost::graph_traits<Graph>::adjacency_iterator AdjVertIt;
   AdjVertIt avi, avinext, av_end;
   tie(avi, av_end)=adjacent_vertices(v,g);
   for (avinext=avi; avi != av_end; avi=avinext)
   {
      ++avinext;
      Vertex vi = *avi;
      clear_vertex(vi,g);
      //******ERROR: avinext appears invalid*******//
   }
}

void DeleteNeighborEdges_OutEdgeIter(Vertex v, Graph& g)
{
   typedef boost::graph_traits<Graph>::out_edge_iterator OutEdgeIt;
   OutEdgeIt oei, oeinext, oe_end;
   tie(oei, oe_end)=out_edges(v,g);
   for (oeinext=oei; oei != oe_end; oei=oeinext)
   {
      ++oeinext;
      Vertex vi = target(*oei,g);
      clear_vertex(vi,g);
      //******ERROR: oeinext appears invalid*******//
   }
}

-- 
View this message in context: http://old.nabble.com/-BGL--adjacency_iterator-invalidation-with-adjacency_list%3ClistS%2C-listS%2C-unorderedS%3E-tp27647214p27713371.html
Sent from the Boost - Users mailing list archive at Nabble.com.

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