Harmonize const-ness in relation navigation return types#204
Harmonize const-ness in relation navigation return types#204tmadlener merged 1 commit intoiLCSoft:masterfrom
Conversation
tmadlener
left a comment
There was a problem hiding this comment.
Is there a use case where you would need to modify the pointed-to contents? If symmetry is the main argument, I would rather add const to other methods than removing them here.
|
My goal would be that people can easily switch from For example, I switched from using EVENT::MCParticle* getMcFromTrack(EVENT::Track* track, const UTIL::LCRelationNavigator& trk2mc){
auto& objects = trk2mc.getRelatedToObjects(track);
auto& weights = trk2mc.getRelatedToWeights(track);
if ( weights.empty() ) return nullptr;
auto maxWeightIdx = std::max_element(weights.begin(), weights.end()) - weights.begin();
return static_cast <EVENT::MCParticle*> (objects[maxWeightIdx]);
}to this EVENT::MCParticle* getMcFromTrack(EVENT::Track* track, const UTIL::LCRelationNavigator& trk2mc){
return static_cast <EVENT::MCParticle*> ( trk2mc.getRelatedToMaxWeightObject(track) );
}and it immediately broke because if I use const EVENT::MCParticle* getMcFromTrack(EVENT::Track* track, const UTIL::LCRelationNavigator& trk2mc){
return static_cast <const EVENT::MCParticle*> ( trk2mc.getRelatedToMaxWeightObject(track) );
}or what I do right now to keep everything as it previously was: EVENT::MCParticle* getMcFromTrack(EVENT::Track* track, const UTIL::LCRelationNavigator& trk2mc){
return static_cast <EVENT::MCParticle*> ( const_cast<EVENT::LCObject*> (trk2mc.getRelatedToMaxWeightObject(track) ));
}so I wouldn't mind switching everything to |
tmadlener
left a comment
There was a problem hiding this comment.
Thanks for the detailed explanation. Given that, I think this is indeed the quickest and easiest solution.
BEGINRELEASENOTES
getRelatedToMaxWeightAndObject(),getRelatedToMaxWeightObject(),getRelatedFromMaxWeightObject()return non-constLCObjectpointer.ENDRELEASENOTES