Boost logo

Boost Users :

Subject: Re: [Boost-users] BGL property maps
From: Sandeep Gupta (gupta.sandeep_at_[hidden])
Date: 2010-05-31 22:30:01


On Mon, May 31, 2010 at 1:09 PM, Arne Schwabe <arne_at_[hidden]> wrote:

> Hi,
>
> I trying to wrap my head about the usage of
> iterator_property_map<RandomAccessIterator, OffsetMap, T, R>
>
> What I am trying to do is the following:
>
>
> create a map like color with key a graph_node and value type of a struct
> like
>
>
> struct foo {
> int numbervists;
> int color;
> }
>
> so I can use that in a breadth first like algorithm. The example shows me
> how to do it for an int but do not know how to change
>
> typedef boost::graph_traits<Graph>::edge_descriptor Edge;
>
> typedef boost::property_map<Graph, boost::id_tag>::type EdgeID_PMap;
> EdgeID_PMap edge_id = get(boost::edge_index(), G);
>
> boost::iterator_property_map<int*, EdgeID_PMap, int, int&>
> capacity_pa(capacity, edge_id), flow_pa(flow, edge_id);
>
> to use foo instead of int. In my understanding, I would have to change int*
> to a RandomAccessIterator to to Iterator that has foo as value type. But I
> am kind of lost how to construct such a thing.
>
> Arne
>
> ___

The following code sample should help you figure it out.

#include <boost/property_map/property_map.hpp>
#include <vector>

struct Foo
{
  int a;
  int b;
};

using namespace boost ;

int main()
{
  int num_nodes = 10;
  std::vector<Foo> foo_store(num_nodes);
  typedef std::vector<Foo>::iterator FooVecIter;
  typedef iterator_property_map<FooVecIter, identity_property_map, Foo, Foo&
> Foo_pmap_t;
  Foo_pmap_t dist_pmap(foo_store.begin(), identity_property_map());

}

-Sandeep



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