add missing const values; use some using instead of typedef#508
add missing const values; use some using instead of typedef#508andreacassioli wants to merge 2 commits into
Conversation
|
Compiler-warning counts vs
|
| const Weight weight_; | ||
| const Distance distance_; | ||
| const Reversed rev_; | ||
| }; |
There was a problem hiding this comment.
I don't think we should use const on private data. The argumentation around my mental model of const has been developed here by Arthur O'dwyer: https://quuxplusone.github.io/blog/2022/01/23/dont-const-all-the-things/
See particularly the "const members are never a good idea" section where he says constness should be enforced by the public API, not by marking private data const: https://quuxplusone.github.io/blog/2022/01/23/dont-const-all-the-things/
Specifically here, the operator is already const so it adds no security:
reference operator[](key_type v) const {
return get(distance_, source(v, g_)) - get(distance_, target(v, g_)) + get(weight_, v);
}And more importantly, a non-static const data member deletes the implicit copy/move assignment operators, and this class is a property map created by make_mapReducedWeight(...) and handed to Dijkstra by value (weight_map(...)). Property maps are value types you copy around so making it non-assignable makes it a non-regular type for no benefit :/
There was a problem hiding this comment.
To be clear, the other changes are great so thank you for this ! ❤️
In hindsight maybe what's missing is a concept check to ensure the maps are not written to ?
BOOST_CONCEPT_ASSERT(( ReadablePropertyMapConcept<Weight, edge_descriptor> ));
BOOST_CONCEPT_ASSERT(( ReadablePropertyMapConcept<Distance, vertex_descriptor> ));There was a problem hiding this comment.
Thanks for the pointers @Becheler I got used to maybe too many const lately and not much time to dig into more C++!
I have made the changes to you propose.
Before submitting
developbranch.Type of change
Does this PR introduce a breaking change?
What this PR does
It superseeds #160
Motivation
Some
constqualifiers are missing. Not a big deal, but it make it clearer to have them in place. Notice that the named parameter interface cannot be changed without introducing a breaking change: the reason is that it defaults to use graph internal property map as output, thus the graph must be modifiable to extract that map.Incidentally I change some
typedeftousing.Testing
Existing tests should be fine
Checklist
b2in thetest/directory).