Iterating over edges of a graph using range-based for
问题 I have a representation of a graph as a std::vector<std::unordered_set<unsigned>> neighbors , that is, vertices are integers, and for each vertex we keep a set of its neighbors. Thus, to walk all edges, I would do something like for (unsigned u = 0; u < neighbors.size(); ++u) for (unsigned v : neighbors[u]) if (u <= v) std::cout << u << ' ' << v << std::endl; Now, I would like to be able to get the same effect from for (auto e: g.edges()) std::cout << e.first << ' ' << e.second << std::endl;