Boost logo

Boost Users :

From: Jeremy Siek (jsiek_at_[hidden])
Date: 2004-05-11 11:12:02


Hi Cyrille,

On May 11, 2004, at 7:29 AM, Cyrille Damez wrote:
> Hi all,
>
>
> I'm currently trying to write a wrapper in order to use the BGL
> algorithms
> and visitors on a home-made graph class. If I'm not mistaken, this
> requires me
> to write (amongst other things) a couple functions that will return
> iterators
> over my graph edges and vertices, eg:
>
> std::pair<graph_traits<MyGraph>::out_edge_iterator,
> graph_traits<MyGraph>::out_edge_iterator >
> out_edges(graph_traits<MyGraph>::vertex_descriptor u,
> const MyGraph& g)
>
> and similarly in_edges(...) , vertices(...) and edges(...) functions.
> However,
> it seems that this function profile forces me to do a const_cast on g
> when
> implementing the function body since the out_edge_iterators are not
> const
> iterators, though they point to internal elements of g.

The BGL iterators are neither const or mutable. Same for the
descriptors.
Instead, mutability is encoded in the property maps. So, for example,
it is okay to
implement out_edge_iterator using a const iterator. See the file
boost/graph/vector_as_graph.hpp for an example. Look at the
implementation of
out_edges, and the val_out_edge_iter class. No const_cast is needed.

Cheers,
Jeremy

_______________________________________________
Jeremy Siek <jsiek_at_[hidden]>
http://www.osl.iu.edu/~jsiek
Ph.D. Student, Indiana University Bloomington
Graduating in August 2004 and looking for work
C++ Booster (http://www.boost.org)
_______________________________________________


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