### boost :: add_vertex()

In this article, let us see the function of boost :: add_vertex in graph construction.
For better understanding, let us use the same example code we used in boost :: boost.graph :: adjacency_list .

#include <boost/graph/adjacency_list.hpp> #include <iostream> using namespace boost; int main() { adjacency_list<> g; adjacency_list<>::vertex_descriptor v1 = add_vertex(g); adjacency_list<>::vertex_descriptor v2 = add_vertex(g); adjacency_list<>::vertex_descriptor v3 = add_vertex(g); adjacency_list<>::vertex_descriptor v4 = add_vertex(g); std::cout << v1 << ", " << v2 << ", " << v3 << ", " << v4 << '\n'; }

So, as we see in the above example code, to add four points to the graph, the  function `boost::add_vertex()` has to be called four times.

`boost::add_vertex()` is a free-standing function and not a member function of `boost::adjacency_list`. You will find there are many free-standing functions in Boost.Graph that could have been implemented as member functions. Boost.Graph is designed to be more of a generic library than an object-oriented library.

`boost::add_vertex()` adds a point to a graph. In graph theory, a point is called vertex, which explains the function name.

`boost::add_vertex()` returns an object of type `boost::adjacency_list::vertex_descriptor`. This object represents a newly added point in the graph. You can write the objects to standard output as shown in the example. The example displays :

The above example identifies points through positive integers. These numbers are indexes to a vector that is used internally in `boost::adjacency_list`. It’s no surprise that `boost::add_vertex()` returns 0, 1, 2, and 3 since every call adds another point to the vector.