Ticket #3416: quick_tour.cpp.patch

File quick_tour.cpp.patch, 2.5 KB (added by Mathieu Malaterre <mathieu.malaterre@…>, 13 years ago)
  • libs/graph/example/quick_tour.cpp

     
    1818using namespace boost;
    1919
    2020template <class Graph> struct exercise_vertex {
    21   exercise_vertex(Graph& g_) : g(g_) { }
     21  exercise_vertex(Graph& g_, const char name_[]) : g(g_),name(name_) { }
    2222  typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
    2323  void operator()(const Vertex& v) const
    2424  {
    2525    using namespace boost;
    2626    typename property_map<Graph, vertex_index_t>::type
    2727      vertex_id = get(vertex_index, g);
    28     std::cout << "vertex: " << get(vertex_id, v) << std::endl;
     28    std::cout << "vertex: " << name[get(vertex_id, v)] << std::endl;
    2929
    3030    // Write out the outgoing edges
    3131    std::cout << "\tout-edges: ";
     
    3636    {
    3737      e = *out_i;
    3838      Vertex src = source(e, g), targ = target(e, g);
    39       std::cout << "(" << get(vertex_id, src)
    40                 << "," << get(vertex_id, targ) << ") ";
     39      std::cout << "(" << name[get(vertex_id, src)]
     40                << "," << name[get(vertex_id, targ)] << ") ";
    4141    }
    4242    std::cout << std::endl;
    4343
     
    4848    {
    4949      e = *in_i;
    5050      Vertex src = source(e, g), targ = target(e, g);
    51       std::cout << "(" << get(vertex_id, src)
    52                 << "," << get(vertex_id, targ) << ") ";
     51      std::cout << "(" << name[get(vertex_id, src)]
     52                << "," << name[get(vertex_id, targ)] << ") ";
    5353    }
    5454    std::cout << std::endl;
    5555
     
    5757    std::cout << "\tadjacent vertices: ";
    5858    typename graph_traits<Graph>::adjacency_iterator ai, ai_end;
    5959    for (tie(ai,ai_end) = adjacent_vertices(v, g);  ai != ai_end; ++ai)
    60       std::cout << get(vertex_id, *ai) <<  " ";
     60      std::cout << name[get(vertex_id, *ai)] <<  " ";
    6161    std::cout << std::endl;
    6262  }
    6363  Graph& g;
     64  const char *name;
    6465};
    6566
    6667
     
    7374  // Make convenient labels for the vertices
    7475  enum { A, B, C, D, E, N };
    7576  const int num_vertices = N;
    76   const char* name = "ABCDE";
     77  const char name[] = "ABCDE";
    7778
    7879  // writing out the edges in the graph
    7980  typedef std::pair<int,int> Edge;
     
    120121  std::cout << std::endl;
    121122
    122123  std::for_each(vertices(g).first, vertices(g).second,
    123                 exercise_vertex<Graph>(g));
     124                exercise_vertex<Graph>(g, name));
    124125
    125126  std::map<std::string,std::string> graph_attr, vertex_attr, edge_attr;
    126127  graph_attr["size"] = "3,3";