GSI Forum
GSI Helmholtzzentrum für Schwerionenforschung

Home » PANDA » PandaRoot » Bugs, Fixes, Releases » std::map not treated properly
Re: std::map not treated properly [message #7744 is a reply to message #7742] Fri, 23 January 2009 17:27 Go to previous message
Bertram Kopf is currently offline  Bertram Kopf
Messages: 110
Registered: March 2006
continuous participant
From: *ep1.ruhr-uni-bochum.de
Hi Mohammad,

Quote:


Theoretically and in principle you are right that when std::map is used with pointers as keys the less operator should be implemented! and usually this is what you read in any STL book with the example of const char pointer and two pointer pointing to the same set of character and then the MAP can not decide it self which one is bigger! but here this is completely meaningless and will never introduce errors unless some body come to the idea to compare two tracks (e.g if (CbmMCTrack *t1 < CbmMCTrack *t2 ) ) what ever this comparison means!

and even if we try to implement this less operator what does it mean here how can a track be less or larger than another?

I think the important thing here is the IsEqual, but this we have as we inherits from TObject so I will not see this as a big problem but as something good to know!



If one uses maps one "has to" guarantee that all functionalities of this template can be used properly. This means that it should be also possible to sort or to compaire things with the methods provided by std::map. Therefore it is mandatory to configure maps correctly. Otherwise it would be very error prone, especially in software projects where more than one developer is involved.

Quote:


another thing which I do not understand is how to solve this with a template? with a base class that define these operator maybe! but template?



The template could look like this:

struct PtrLess {
template<class PtrType>
bool operator()(PtrType ptr1, PtrType ptr2) const {
return (*ptr1) < (*ptr2);
}
};


This requires that in each key object the less operator is reasonably defined.

Quote:


My suggestion is to try to use TMAP from root instead of STL MAP, it is at least faster and then you are always sure that TObjects are inside so you do not care much about this!



I am not sure but I think it is a question of tast to use TMap or std::map.

Cheers,
Bertram.

 
Read Message
Read Message
Read Message
Previous Topic: PndHypHit build error
Next Topic: G4MagIntegratorDriver error
Goto Forum:
  


Current Time: Fri Apr 19 03:02:37 CEST 2024

Total time taken to generate the page: 0.01087 seconds