I am trying to figure out how to use boost::graph to store some information. However, there is information I want tied to each vertex. Staring at the documentation for the l
I consider Boost.Graph to have a very good documentation, but not truly for beginners on the matter. So here goes an example that i hope is simple enough !
//includes
// Create a name for your information
struct VertexInformation
{
typedef boost::vertex_property_type type;
};
// Graph type, customize it to your needs
// This is when you decide what information will be attached to vertices and/or edges
// of MyGraph objects
typedef boost::adjacency_list > MyGraph;
int main()
{
MyGraph graph;
// Create accessor for information
typedef boost::property_map::type InformationAccessor;
InformationAccessor information( get( VertexInformation(), graph ) );
// Create a vertex (for example purpose)
typedef boost::graph_traits::vertex_descriptor MyVertex;
MyVertex vertex = add_vertex( graph );
// Now you can access your information
put( information, vertex, 1. );
// returns 1 !
get( information, vertex );
return 0;
}