Boost logo

Boost :

From: Jeremy Siek (jsiek_at_[hidden])
Date: 2001-07-19 07:54:05


Hi Rob,

The simple answer is that you could think about them as const iterators
(but that answer is slightly inaccurate).

The graph iterators technically are neither const or non-const. The
const-ness of a normal STL-style contaiiner iterator says whether you can
change the stored object... in the case of the graph iterators, the result
of dereferencing is not some stored object, but instead a vertex or edge
descriptor, which is just a handle, or a positional marker so to speak.
Constness only comes into play when you start to talk about accessing the
properties attached to vertices or edges. This accessing is done through
property maps, and property maps come in both const and mutable varieties.

Also, you mention changing neighbors... to add (or remove) edges from a
graph you must pass the graph object into the add_edge() function, and the
graph object must be non-const. The add_edge() function also takes a
couple vertex_descriptor objects, but again, these are just "positional"
markers, and do not have constness.

Hope this helps,
Jeremy

On Thu, 19 Jul 2001, Rob Smallshire wrote:

> I'm using the Boost graph library at the moment, and just getting the
> hang of the vast number of iterator types I have to play with.
>
> With the boost::graph_traits<>::adjacency_iterator(which is
> dereferencable to a vertex descriptor), what are the const semantics
> (intended and/or implemented) of this iterator ?
>
> Presumably, I can't change the neighbours of a vertex by fiddling
> with what the adjacency_iterators returned by adjacent_vertices() are
> pointing to ? So is it behaving as a 'const_adjacency_iterator' even
> though it doesn't have this name ?
>
> This is important to me because my class (which contains a Boost
> graph), needs to be able to return a list of neighbours for a given
> vertex. I could copy the list of neighbours into a container and
> return a reference to the container, but it would be nicer to just
> return the adjacency_iterators to the client code for my class, but I
> don't want the client code to be able to modify the data in my class,
> so the iterators should be the equivalent of const_iterators.
>
> Thoughts/comments ?
>
> Rob Smallshire
>
>
>
>
> Info: http://www.boost.org Unsubscribe: <mailto:boost-unsubscribe_at_[hidden]>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>

----------------------------------------------------------------------
 Jeremy Siek www: http://www.lsc.nd.edu/~jsiek/
 Ph.D. Candidate, IU B'ton email: jsiek_at_[hidden]
 Summer Manager, AT&T Research phone: (973) 360-8185
----------------------------------------------------------------------


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