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 MapSorting in the class

  std :: map & lt; Std :: string, std :: vector & lt; Electrons & gt; & Gt; M_mymap;  

I am interested in the ordering in the short order using the member function, so that if I

  Std :: vector & lt; Electrons & gt; Veto_electrons = m_mymap ["veto"];  

then veto_aculator [0] is always the highest electron with pt .

I could probably write one fun to work on, but primarily as a drill, I used the operator I want to surcharge if possible.

Also some of my feedback code from the real programmer, I'm not a professional, but I like and like programming!

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 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.

Note : I did not override the operator [] . So do not use it to enter.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -