I'm using boost::graph
and I have two vertex_descriptor
s. What is the quickest way to get the edge between them, without iterating over all the edges?
Asked
Active
Viewed 1.3k times
28

Amir Rachum
- 76,817
- 74
- 166
- 248
2 Answers
58
Ok, I found it out. boost::edge(u,v,g)
returns pair<edge_descriptor, bool>
where the bool
is whether the edge exists. So in my case I know it does, so I use the expression:
boost::edge(u,v,g).first

Amir Rachum
- 76,817
- 74
- 166
- 248
-
2Actually, it should be `boost::edge(u,v,g).second`, if you want the `bool` value... – tnull Feb 17 '15 at 11:16
-
3@tnull since I know the edge exists and I'm looking for the edge itself, `first` is the attribute I need. – Amir Rachum Apr 08 '15 at 17:15
7
There is also a function boost::lookup_edge()
in boost/graph/lookup_edge.hpp
; that function dispatches to either edge()
or out_edges()
and a search based on the particular graph type you are using.

Jeremiah Willcock
- 30,161
- 7
- 76
- 78