Boost logo

Boost Users :

From: Doug Gregor (dgregor_at_[hidden])
Date: 2004-11-24 12:22:45


On Nov 24, 2004, at 11:21 AM, TC MA wrote:
> Still has a compile problem.
> interior_property_map.cpp is now:
>
> struct vertexStruct {
> string name;
> };
>
> template <class EdgeIter, class Graph>
> void who_owes_who(EdgeIter first, EdgeIter last, const
> Graph& G)
> {
> // Access the propety acessor type for this graph
> typedef typename property_map<Graph,
> &vertexStruct::name>::const_type NamePA;

My mistake, this would have needed to be:
   typedef typename property_map<Graph, string
(vertexStruct::*)>::const_type NamePA;

But, this shows us just how different bundled properties are from the
prior types of properties. The property_map class becomes harder to
use, but in many cases is not necessary. At the end is my rewrite of
the example, which illustrates how much less baggage we need to worry
about when we go all-out with bundled parameters.

        Doug

template <class EdgeIter, class Graph>
void who_owes_who(EdgeIter first, EdgeIter last, const Graph& G)
{
   while (first != last) {
     cout << G[source(*first, G)].first_name << " owes "
          << G[target(*first, G)].first_name << " some money" << endl;
     ++first;
   }
}

struct VertexData
{
   string first_name;
};

int
main()
{
   {
     // Create the graph, and specify that we will use std::string to
     // store the first name's.
     typedef adjacency_list<vecS, vecS, directedS, VertexData>
MyGraphType;

     typedef pair<int,int> Pair;
     Pair edge_array[11] = { Pair(0,1), Pair(0,2), Pair(0,3), Pair(0,4),
                             Pair(2,0), Pair(3,0), Pair(2,4), Pair(3,1),
                             Pair(3,4), Pair(4,0), Pair(4,1) };

     MyGraphType G(5);
     for (int i=0; i<11; ++i)
       add_edge(edge_array[i].first, edge_array[i].second, G);

     G[0].first_name = "Jeremy";
     G[1].first_name = "Rich";
     G[2].first_name = "Andrew";
     G[3].first_name = "Jeff";
     G[4].first_name = "Doug";

     who_owes_who(edges(G).first, edges(G).second, G);
   }

   cout << endl;

   return 0;
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net