highest value in a stl map C++? -


I have a map like this with enum as the key and uint value.

  #include & lt; Iostream & gt; #include & lt; String & gt; # Include & lt; Map & gt; using namespace std; Typedef enum tcGroup_t {CG_NONE = 0, CG_BASE = 1, CG_RC = 3, CG_HTD = 4, CG_HID = 5} tcGroup; Int getMaxtcGroupCount () {std :: map & lt; TcGroup, UINT & gt; MaxTcGroup; MaxTC Group [CG_BASE] = 2; MaxTeC Group [CG_HID] = 33; MaxTC Group [CG_HTD] = 44; MaxTeC Group [CG_RC] = 87; MaxTC Group [CG_NONE] = 39; }  

Actually, I want to return the highest value in the calling function in the map. In the above case, I want to return the value 87. I know that the map is ordered through the key, but in my case I want to return the highest value in the map?

Any help is appreciated. Thanks

You can use it with a suitable functor.

  bool CMP (constants std :: pair  & amp; ;;h; constant; std :: pair & gt; & Amp; LHS) {Return rhs.second & lt; Lhs.second; }  

then

  auto max_iter = max_element (maxTcGroup.begin (), maxTcGroup.end ());  

Comments