Boost logo

Boost Users :

Subject: Re: [Boost-users] [BGL] iterator/descriptor invalidation
From: Dmitry Bufistov (dmitry_at_[hidden])
Date: 2008-12-10 05:50:40


Andrew Sutton escribió:
>
> In the provided example
> g.m_vertices.reserve(6)
> helps.
>
>
> You're right... That should work - unless you're adding more than 6
> vertices.
>
> Maybe we should provide a reserve_vertices(g, n) function for the vertex
> set on adjacency lists. It's a nice optimization and apparently can help
> avoid some invalidation. Obviously it only applies to VertexSet == vecS
> || listS. Thoughts?
>

Looks like everything works fine with undirected graph, i.e., this code
does not lead to segfault:

#include <iostream>
#include <boost/graph/adjacency_list.hpp>

using namespace boost;

typedef adjacency_list<listS, vecS, undirectedS > Graph;

int main() {
   Graph g(3);
   add_edge( 0, 1, g );
   add_edge( 1, 2, g );
   add_edge( 2, 0, g );

   Graph::edge_iterator ei, ei_end;
   for( tie( ei, ei_end ) = edges( g ); ei != ei_end; ++ei )
     {
       add_vertex( g );
     }
}

Regards,
Dmitry


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