boost : : vertices()

boost : : vertices()

In this article, we will see how to access vertices using boost : : vertices().

#include <boost/graph/adjacency_list.hpp> #include <utility> #include <algorithm> #include <iterator> #include <iostream> using namespace std; using namespace boost; int main() { adjacency_list<> g; add_vertex(g); add_vertex(g); add_vertex(g); add_vertex(g); pair<adjacency_list<>::vertex_iterator,adjacency_list<>::vertex_iterator> vs = vertices(g); copy(vs.first, vs.second, ostream_iterator<adjacency_list<>::vertex_descriptor>{ cout, "\n"}); }

We've already seen the functions of adjacency_list and add_vertex()in the previous articles.
To get all points from a graph, call boost::vertices(). This function returns two iterators of type boost::adjacency_list::vertex_iterator, which refer to the beginning and ending points. The iterators are returned in a std::pair. The above code uses the iterators to write all points to standard output. 

The output of the above example is displayed as follows: