Boost logo

Boost Users :

From: Sebastian Weber (sebastian.weber_at_[hidden])
Date: 2005-07-22 13:50:01

Hi Doug!

>>typedef boost::adjacency_list<boost::vecS, boost::vecS,
>>boost::undirectedS > graph_t;
>>typedef boost::my_edge_iterator<base_rand_gen_t, graph_t> SFGen;
>>graph_t bg = graph_t(SFGen(bg, base_rand, 100), SFGen(), 100);
>>This code compiles fine, but seg-faults immediatly since bg does not
>>seem to be defined when my iterator gets constructed.
> My gut feeling is that this should work.. you're not trying to make a
> copy of "bg" when you builf SFGen, right? SFGen needs to store a
> pointer to a graph_t, not a reference or copy.

Yes thats right, I only need a pointer/reference to the graph object
which is going to be constructed. I guess the trouble with the statement
above is that I first construct the SFGen-object and give this as an
argument to the constructor of my graph-object which I want to build. I
dont know if just my compiler fools me or if there is actually a way to
do this. I have a debian sarge system with gcc-3.3 and latest cvs boost.

>> A solution would
>>be to provide a add_edge_range-function which gets as input the
>>EdgeIterator and the corresponding empty boost graph.
> Good idea.

Actually I copied the code from the adjacency_list.hpp and renamed it to

template <class Graph, class EdgeIterator>
void build_graph(Graph& g,
                 EdgeIterator first, EdgeIterator last)
   typedef graph_traits<Graph> gtraits;

   typename gtraits::vertex_descriptor* v = new typename
   typename gtraits::vertex_iterator vi, vend;
   std::size_t i = 0;
   cout << "Initializing vertex list ..." << endl;
   for (tie(vi, vend) = vertices(g); vi != vend; ++vi)
     v[i++] = *vi;

   cout << "Populating graph ..." << endl;
   while (first != last) {
     add_edge(v[(*first).first], v[(*first).second], g);
   cout << "done building graph" << endl;

   delete [] v;

It does what I want, but using the constructor would be nicer.



Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at