Boost logo

Boost :

From: Tim Culver (tim.gmane_at_[hidden])
Date: 2002-09-17 08:16:26


Oops, that's what I get for posting made-up code snippets. What I meant
was:

typedef adjacency_list<listS, listS, ...> Graph;
typedef graph_traits<Graph>::vertex_descriptor Vdesc;
typedef graph_traits<Graph>::edge_descriptor Edesc;
typedef graph_traits<Graph>::vertex_iterator Viter;
typedef graph_traits<Graph>::edge_iterator Eiter;

Vdesc find_vertex(Graph& g) {
   Viter v, v_end;
   for (tie(v, v_end)=g.vertices(); v!=v_end; v++)
     if (my criterion)
       return *v;
   return Vdesc();
}

I could just return a Viter instead of a Vdesc. But I have lots of code
that finds it convenient to hold on to vertex descriptors instead of
iterators. Mixing them would be a lot of trouble, since you can't
efficiently convert a descriptor to an iterator. I'd have to switch to
use iterators throughout.

Also, I think the convention above might be a good alternative. I
notice that the vertex descriptor does have a default constructor. My
question is, does a default-constructed vertex descriptor act like a
null value, in that it never corresponds to a valid vertex, and two
nulls always compare equal? The documentation specifies that the
default constructor and operator== must be defined, but the semantics
are not specified.

http://www.boost.org/libs/graph/doc/Graph.html

Thanks for your response, David!

Tim


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk