Boost logo

Boost Users :

From: Doug Gregor (dgregor_at_[hidden])
Date: 2004-11-24 00:07:08


On Nov 23, 2004, at 10:56 PM, TC MA wrote:
> // create a tag for our new property
>
> enum vertex_first_name_t { vertex_first_name };
> namespace boost {
> BOOST_INSTALL_PROPERTY(vertex, first_name);
> }

You won't actually need the part above this any more.

> 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;

The compiler is actually giving a somewhat useful message here: add an
'&' before the vertexStruct::name to form a pointer-to-member.

> NamePA name = get(vertex_first_name, G);

Here again, you'll want to use a pointer-to-member, like this:

NamePA name = get(&vertexStruct, G);

> typedef typename
> boost::property_traits<NamePA>::value_type NameType;
>
> NameType src_name, targ_name;
>
> while (first != last) {
> src_name = boost::get(name, source(*first,G));
> targ_name = boost::get(name, target(*first,G));

Now you can use the simpler:

        src_name = G[source(*first, G)].name;
        targ_name = G[target(*first, G)].name;

Once you've replaced the original get calls with these lines, you can
remove the definition of the "name" variable as well.

        Doug


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