c++ - map<string, object> sort according to object member function value -
I'm trying to load more than a class operator I wrote (facing the real situation ) To organize the map of a member of the square.
Here I created a tar ball with my code:
There I am interested in the ordering in the short order using the then I could probably write one fun to work on, but primarily as a drill, I used the Also some of my feedback code from the real programmer, I'm not a professional, but I like and like programming! MapSorting in the class
std :: map & lt; Std :: string, std :: vector & lt; Electrons & gt; & Gt; M_mymap;
Std :: vector & lt; Electrons & gt; Veto_electrons = m_mymap ["veto"];
veto_aculator [0]
is always the highest electron with pt
. operator
If you want to assume that the elements of the map are sorted, then the simplest (Writing at least code perspective) may be to override the entry method in the map and use only this:
class My_map: public stadium :: map & lt; Std :: string, std :: vector & lt; Electrons & gt; {// Whatever constructor you get here std :: pair and lt; Iterator, bool & gt; Insert (value_type vt) {// Make sure vector & lt; Electrons & gt; Has been sorted! Std :: sort (vt.second.begin (), vt.second.end (), [] (Const Electrons & one, const electrons & amp; amp; amp; amp; amp; Amp; one); a.pt ()> gt; bpt); // then return it to std :: map & lt; Std :: string, std :: vector & gt; Electronon & gt; :: insert (vt); }};
Now, a lot of people can consider this "bad behavior" because the Note : I did not override the std :: map
does not provide the virtual constructor, so it will not be Should be inherited. That's why you have to std :: map & lt; ... & gt; *
do not make you dynamically start with my_map
. Alternatively, you can send my_map
to std :: map & lt; ... & gt; Members can create and do the same - but this requires a ton more typing and basically copy the whole interface I will do it this way.
operator []
. So do not use it to enter.
Comments
Post a Comment