|
Boost Users : |
From: Björn Lindberg (yg-boost-users_at_[hidden])
Date: 2002-10-02 09:17:13
I have two questions regarding the design of the BGL. I'm interested in
this to get a better understanding of the design choices, which
influences how I use the BGL and how I'm building on it.
1) Why is a lot of the function arguments made by value rather than
reference? As an example, consider the BFS algorithm, where the
documentation states that
"[1] Since the visitor parameter is passed by value, if your visitor
contains state then any changes to the state during the algorithm will
be made to a copy of the visitor object, not the visitor object passed
in. Therefore you may want the visitor to hold this state by pointer or
reference."
It would be much easier to use the visitor objects for keeping state
throughout the algorithm if it was passed by reference instead.
2) Non-constness. It seems impossible to use BGL together with code that
is "const-correct". If, for instance, I have a function implementing
some kind of examining algorithm on a graph (so the graph is passed to
it as const), and this algorithm uses breadth_first_search with a
visitor that doesn't modify the graph, it still can't be const when
passed to breadth_first_search. This only leaves the options of either
(i) casting away constness in the call, which is bad because it could
introduce bugs later on, or (ii) leaving out const altogether which is
not good either.
Maybe I've just misunderstood something and this is possible, or perhaps
it is impossible to implement BGL in this way?
Björn
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