Boost logo

Boost Users :

Subject: [Boost-users] [BGL] property_map for or with bundled properties
From: Cedric Laczny (cedric.laczny_at_[hidden])
Date: 2010-11-12 10:43:50


Hi,

I was trying to use an iterator_property_map with bundled properties and ran
into difficulties. For those having thought about that, I want to post my
solution and also address a question.

Let's start with the solution:
Imagine, one uses bundled properties and has defined the following
EdgeProperty:
struct EdgeProperty{
  int edge_index;
}
and
typedef adjacency_list<...> Graph;

Whether this makes sense or not may also be discussed but is not important for
the demonstration purposes.

So if you now want to define an iterator_property_map that is based on the
edge_index, it get's IMHO a bit more complicated than using internal
properties:
  typedef property_map<Graph, int EdgeProperty::*>::type EdgeIndexMap;
  EdgeIndexMap e_index = get(&EdgeProperty::edge_index,g);
  std::vector< int > flag_vec(num_edges(g), 0);
  // Create the external property map
  iterator_property_map< std::vector< int >::iterator, EdgeIndexMap >
        flags(flag_vec.begin(), e_index);

versus an example using vertex_index that is automatically created when using
vecS for the vertices:
  typedef property_map<Graph, vertex_index_t>::type VertexIndexMap;
  VertexIndexMap v_index = get(vertex_index, g);
  std::vector< int > flag_vec(num_vertices(g), 0);
  // Create the external property map
  iterator_property_map< std::vector< int >::iterator, VertexIndexMap >
        flags(flag_vec.begin(), v_index);

So far for the solution.

I have also a question in this place:
What does the "EdgeProperty::*" exactly do? The EdgeProperty is of course the
bundle, but what about the "::*" is this some sort of RegEx for "all
attributes of this bundle"?
I looked at the code in properties.hpp and was able to generally understand
the idea, but it did not become clear to me why the "::*" is needed.

Thank you.

Best,

Cedric


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