Boost logo

Boost Users :

From: Aaron Windsor (aaron.windsor_at_[hidden])
Date: 2007-11-06 21:18:34


On 11/5/07, Ferng, Andrew D <andrew.d.ferng_at_[hidden]> wrote:
> Hi Aaron,
> Thanks for the help! Still trying to understand how to use BGL.
>
> As for the original graph type, I was using:
> typedef adjacency_list<
> vecS,
> vecS,
> undirectedS,
> property<vertex_index_t, long>,
> property<edge_index_t, long> > ConnectionGraph;
>
> Having had no luck with it, I changed it back to the example using name
> / string and then it worked.
>
> typedef adjacency_list<
> vecS,
> vecS,
> undirectedS,
> property<vertex_name_t, std::string>,
> property<edge_name_t, std::string> > ConnectionGraph;
>
> So I'm still confused as to why it would be a l-value issue in one case
> but not in the other.
> In both of these situations, the goal is trying to populate the property
> map right?

Vertex index maps and edge index maps are special cases - they
shouldn't be used for any purpose but for mapping all vertices (or
edges, respectively) in the graph g to unique indices in the range
[0..num_vertices(g)) (or num_edges(g), respectively). Such a property
map is useful because if you have a vertex or edge index map that
returns indices in constant time, you can create constant-time
property maps that map vertices/edges to _any_ type T by composing the
vertex/edge index map with a std::vector that holds values of type T.
If you need a property map to store something else, like a label for
each vertex, you should use some other property map type (as you did
above, with vertex_name_t or edge_name_t), or better yet, use bundled
properties.

As to why you get an lvalue property map in one case and an rvalue
property map in the other case - if you store your vertices in a
std::vector, the vertex index map can be provided for you, since the
"vertex index" for each vertex can just be the index at which the
vertex is stored. On the other hand, if you store vertices in a
std::list, there's no natural association between vertices and the
range [0..num_vertices(g)), so you have to populate one yourself (and
these indices are stored internally along with the storage for the
vertices). So, the mechanism used to provide the vertex index map is
different depending on whether you store vertices in a vector or a
list - in one case (list), you can put things into the map, in the
other case (vector), you can't.

Regards,
Aaron


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