Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2000-09-19 16:41:34


----- Original Message -----
From: "jeremy siek" <jsiek_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Tuesday, September 19, 2000 5:15 PM
Subject: Re: [boost] Graph stuff

> David Abrahams writes:
> > Do you think we could have one of these instead?
> >
> >
> > edge_property<Graph, edge_capacity>::type capacity
> > = edge_property(G, edge_capacity());
> > edge_property<Graph, edge_flow>::type flow
> > = edge_property(G, edge_flow());
>
> As one of the reviewers mentioned, this could be confusing because it
> sounds like you are accessing a property value instead of a property
> accessor.

I don't see the problem here. You _are_ accessing the property... of the
entire graph! Then you can index the property with the particular edge or
vertex descriptor (you didn't throw out operator[] for property-accessors,
did you?) It makes complete sense to me (of course ;)), and I think that
once you've been exposed to the structure (graph->property->property-value)
the first time there are fewer constructs to remember.

> > or better yet:
> >
> > // using static template member functions
> > edge_capacity_type<Graph>::type capacity = edge_capacity::get(G);
> > edge_flow_type<Graph>::type flow = edge_flow::get(G);
> >
> > or maybe:
> >
> > property_traits<Graph, edge_capacity>::type capacity =
> > edge_capacity::get(G);
> > property_traits<Graph, edge_flow>::type flow = edge_flow::get(G);
>
> Since 'property_traits' is already taken, how about:
>
> property_accessor<Graph, edge_capacity>::type
> capacity = accessor(G, edge_capacity());
>
> or if you prefer using a static member function:
>
> property_accessor<Graph, edge_capacity>::type
> capacity = edge_capacity::accessor(G);
>
> One caveat to this is that implementing this will require a little
> meta-programming to distinguish beteen edge and vertex property tags.

That's why I suggested using edge_property<Graph, edge_capacity>::type
I still prefer edge_capacity::get(G) to get the edge_capacity of the entire
graph.

> > And then some convenience functions:
> >
> > edge_capacity::get(G, edge_descriptor) // to get an edge_capacity
> > edge_capacity::set(G, edge_descriptor, value) // to set an edge
capacity
> >
> > If you want to call it put(), that's OK too I guess.
>
> I'm not sure why you'd ever want these. The property accessor
> interface already handles this:
>
> property_accessor<Graph, edge_capacity>::type
> capacity = edge_capacity::accessor(G);
>
> get(capacity, e)
> set(capacity, e, c);
[I thought you nixed "set"]

It's the same reason we have make_pair(). Because it's way too da*n much
typing/reading to write:

    property_accessor<Graph, edge_capacity>::type
      capacity = edge_capacity::accessor(G);
    get(capacity, e)
    put(capacity, e, c)

and still too much to write:

  get(edge_capacity::accessor(G), e)
  put(edge_capacity::accessor(G), e, c)

I just want to say

  edge_capacity::get(G, e)
  edge_capacity::put(G, e, c)

The more tokens you make people type/read the less usable your library is,
and the less maintainable your users' code is.

-Dave


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk