Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2002-09-16 16:37:39


From: "Tim Culver" <tim.gmane_at_[hidden]>

> I read an archived discussion of vertex and edge descriptors, but I'm
> not sure I understood it. Is this the proper way to handle these:
>
> typedef adjacency_list<listS, listS, ...> Graph;
> typedef graph_traits<Graph>::vertex_descriptor Vdesc;
         ^
> typedef graph_traits<Graph>::edge_descriptor Edesc;
         ^
You're missing typename here.

> Vdesc find_vertex(Graph& g) {
> Vdesc v, v_end;
> for (tie(v, v_end)=g.vertices(); v!=v_end; v++)

IIRC, g.vertices() returns a pair of graph_traits<Graph>::vertex_iterator,
not vertex_descriptor

> if (my criterion)
> return v;
> return Vdesc();

I'm pretty sure there's no notion of a "none" vertex descriptor. Why don't
you just return an appropriate vertex_iterator?
v_end would be a good choice (if you change those to vertex_iterators).

> Vdesc v = find_vertex(g);
> if (v != Vdesc()) {
> // found
> } else {
> // not found
> }
>
> 1. Is this correct as written? (Semantically, I mean--does it do what I
> obviously want it to do?)

I don't think so.

> 2. Is this still correct if I change both listS to vecS?

I think it's still wrong in all the same ways (and no new ways).

-----------------------------------------------------------
           David Abrahams * Boost Consulting
dave_at_[hidden] * http://www.boost-consulting.com


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