graph-v2
graph-v2 copied to clipboard
Concept `index_adjacency_list` is underconstrained
Consider this graph representation that contains a bug in the adaptation to the Graph Container Interface:
namespace MyLibrary
{
struct MyEdge {
std::string content;
int indexOfTarget;
std::string target_id(auto&&) const { return "0"; } // BUG: return type of `target_id` is different than `graph::vertex_id_t<MyLibrary>`
};
struct MyVertex {
std::string content;
std::vector<MyEdge> outEdges;
std::vector<MyEdge> const& edges(auto&&) const { return outEdges; }
};
class MyGraph {
std::vector<MyVertex> _vertices;
public:
std::vector<MyVertex> const& vertices() const { return _vertices; }
};
std::vector<MyEdge> const& edges(MyGraph const& g, int uid) { return g.vertices()[uid].edges(g); }
int target(MyGraph const& g, MyEdge const& uv) { return uv.indexOfTarget; }
}
This satisfies the concept graph::index_adjacency_list but trying to instantiate graph::dijkstra_shortest_paths ends in failure for obvious reasons.
Recommendation:
The customization point target_id should have an additional constraint that its type convertible to vertex_id_t<G> (or maybe, be exactly vertex_id_t<G>).