Boost logo

Boost Users :

From: Douglas Gregor (doug.gregor_at_[hidden])
Date: 2005-07-12 08:25:06


On Jul 11, 2005, at 11:39 PM, Abhijit Deshmukh wrote:

> Hi,
>
> I have a mutable property undirected graph. I want to delete all the
> vertices and edges in the graph.
>
> I tried using the for loop
>
> for( b = *vertices( databaseGraph ).first; b!= *vertices(
> databaseGraph ).second; b++ ){
> clear_vertex( b, databaseGraph );
> remove_vertex( b, databaseGraph );
> }

The major problem here is that you shouldn't be dereferencing
vertices(databaseGraph).second, because it is a past-the-end iterator.
You could rewrite the loop as:

while (vertices(databaseGraph).first != vertices(databaseGraph).second)
{
   b = *vertices(databaseGraph).first;
   clear_vertex(b, databaseGraph);
   remove_vertex(b, databaseGraph);
}

> Can you let me know what is the correct way of deleting all edges and
> vertices in a mutable property undirected graph.

The easy way is just "databaseGraph.clear()"

        Doug


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