Returning a Null Edge Descriptor in an adjacency list [C++ BGL]

Viewed 68

After asking for advice on how to find an edge in an undirected graph I was looking to adjust his function to return a null edge if it cannot find one. I know that boost has a null vertex (graph_traits<G>::null_vertex()) but I haven't found one for edges in any documentation. Does anyone have a solution for said problem?

1 Answers

There is no null edge. Depending on your graph model you can conceive of one, but that's gonna mean you have to

  • use implementation details (specifically, nullptr could be a good fit, but will never be safe to use with any BGL function)
  • make your own model of a graph concept so you control the implementation details

In practice, I'd use a vocabulary type that expresses the intent. E.g. if you had a search function that returns an edge unless none can be found, I'd return:

std::optional<edge_descriptor> my_search();
Related