On Tue, 29 Jun 2010, W.P. McNeill wrote:
It looks like the adjacency_iterator created by adjacency_iterator_generator was being defined in terms of vertex_descriptor and out_edge_iterator, which are in turn defined via graph_traits<>, which would cause this problem. I got a little closer to an ideal solution by putting
typedef ring_adjacency_iterator adjacency_iterator;
in the graph class and forward-defining ring_adjacency_iterator, then later on in implicit.hpp deriving ring_adjacency_iterator from boost::adjacency_iterator like so
class ring_adjacency_iterator:public boost::adjacency_iterator< graph, vertex_descriptor, out_edge_iterator, boost::use_default> { public: typedef boost::adjacency_iterator< graph, vertex_descriptor, out_edge_iterator, boost::use_default> parent_class; ring_adjacency_iterator() {}; ring_adjacency_iterator(const out_edge_iterator& ei, const graph* g): parent_class(ei, g) {}; };
I didn't have to typedef the adjacency_iterator to void in the graph definition, so this is a valid AdjacencyGraph model.
I like this better than writing my own iterator_adaptor because it uses boost::adjacency_iterator, though it feels a little hacky because the body of ring_adjacency_iterator is mostly cut-and-pasted from adjacency_iterator.hpp.
I'd like to find a way to define the adjacency iterator with the generator using the statement
boost::adjacency_iterator_generator
::type but I haven't been able to do it. This generator statement relies on graph_traits<> properties vertex_descriptor and out_edge_iterator, so has to come after the definition of implicit_ring::graph. But that means I have to have a forward declaration of the adjacency_iterator, and I don't know how to forward-declare something I'm getting from boost::adjacency_iterator_generator<>::type.
It's still pretty good, but if this is going to be example code I'd like to make sure I'm doing it the best way possible.
You have the actual types that vertex_descriptor, etc. are defined to, right? Can you use those as the arguments to adjacency_iterator_generator? -- Jeremiah Willcock