Boost logo

Boost Users :

From: Douglas Gregor (doug.gregor_at_[hidden])
Date: 2005-03-17 23:33:05


On Mar 16, 2005, at 8:10 PM, Elvanör wrote:

> I just use, if I have a graph of type Graph (it is in fact an
> adjacency list, but that is unimportant),
>
> typedef typename Graph:vertex_bundled VertexType;
>
> But I am still wondering if it is the "correct solution". For me it
> works, however I don't understand why I use directly
> Graph:vertex_bundled and not some kind of
> graph_traits<Graph>::vertex_bundled thing...

Because I was lazy :) We really should have
"vertex_bundle_type<Graph>::type" and "edge_bundle_type<Graph>::type"
traits, which are defined for graphs that have bundled properties.

> I am new to traits (be it for STL iterators or Boost Graphs ) and
> don't understand how it works internally (I just understand the basic
> concept yet, and know how to use them). What is the whole purpose of
> having a graph_traits class if something as simple as
> Graph:vertex_bundled works? Why am I doing things like
> graph_traits<Graph>::vertex_descriptor instead of just
> Graph::vertex_descriptor then ??

The reason that we use graph_traits<Graph>::foo instead of Graph::foo
is that you can add graph_traits<Graph>::foo even if you can't change
the type Graph. If we always relied on having a member type "foo", we'd
always have to change the graph type to put that type "foo" in. Check
out, for instance, the vector_as_graph module: it makes a vector of
edge lists into a graph, without changing the vector at all.
graph_traits makes that possible.

> Any help would be appreciated, and I still think the documentation
> should mention how to get the type of the bundled properties.

You're absolutely correct. I've just added the aforementioned traits
with some documentation for them (within the description of bundled
properties).

        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