Boost logo

Boost Users :

From: sa3h1n sa3h1n_at_[hidden])
Date: 2003-01-07 17:30:31


BGL gurus:

I would like to use listS for vertex and edge lists because of
iterator stability.

However, if I run the following code:

------------
    // use listS
    typedef adjacency_list<listS, listS> Pgraph;
    // use vecS
    typedef adjacency_list<vecS, vecS> Pgraph2;

    int num_vertices = 2;
    Pgraph pg (num_vertices);
    boost::graph_traits<Pgraph>::vertex_iterator vi, vi_end;
    boost::tie(vi, vi_end) = vertices(pg);

    Pgraph2 pg2 (num_vertices);
    boost::graph_traits<Pgraph2>::vertex_iterator vi2, vi_end2;
    boost::tie(vi2, vi_end2) = vertices(pg2);

    for (vi, vi2; vi != vi_end && vi2 != vi_end2; vi++, vi2++)
    {
            std::cout << *vi << std::endl;
            std::cout << *vi2 << std::endl;
    }
------------

I get the following output:

------------
0x00146e60 <- this is *vi which uses listS
0 <- this is *vi2 which uses vecS
0x00146e78 <- this is *vi which uses listS
1 <- this is *vi2 which uses vecS
------------

One of the problems with this is when I try to display the graph
using write_graphviz. Vertex indices turn out be 0x0014e60 etc
instead of nice numbers like 0, 1, etc.

Tracing execution through the debugger, it appears that vi and
vi_end are of type generic_iterator(), whereas vi2 and vi2_end are
of type iterator_adaptor() defined in boost/iterator_adaptors.hpp .
Unfortunately, this is where my c++ expertise peters out.

So what is happenning here? And is there anything I can do to ensure
iterator stability while using vecS?

Any help will be much appreciated,
S


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