2

Can I ask what the <> is for in adjacency_list<> ? I am new to stl. I know I can define a container like this: vector<int> vec, but why here it is empty in <>? Thank you.

#include <boost/graph/adjacency_list.hpp>
    using namespace boost;
    adjacency_list<> g;
    // adds four vertices to the graph
    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);
daydayup
  • 2,049
  • 5
  • 22
  • 47
  • possible duplicate of [Template default arguments](http://stackoverflow.com/questions/15373823/template-default-arguments) – Pradhan Jul 12 '15 at 19:30

1 Answers1

4

It's because adjacency_list is a templated type. You must specify <> when using C++ templates.

The full definition for the type is:

template <class OutEdgeListS = vecS,
          class VertexListS = vecS,
          class DirectedS = directedS,
          class VertexProperty = no_property,
          class EdgeProperty = no_property,
          class GraphProperty = no_property,
          class EdgeListS = listS>
class adjacency_list
{
    ...
}

Notice that each template parameter has a default: vecS, vecS, directedS, no_property, no_property, no_property, listS, respectively.

The empty <> means you want the default classes for the template parameters. By not specifying the specific values for the template parameters, you get the defaults.

The reason <> is needed, and can't be left out (which would be nice, yes) is because of the way the C++ language has been defined. You can avoid it by using a typedef, but ultimately the angle brackets are required for using template types.

Community
  • 1
  • 1
Cornstalks
  • 37,137
  • 18
  • 79
  • 144