C++ How to find the biggest key in a std::map?

后端 未结 4 997
走了就别回头了
走了就别回头了 2020-12-14 00:00

At the moment my solution is to iterate through the map to solve this.

I see there is a upper_bound method which can make this loop faster, but is there

4条回答
  •  情深已故
    2020-12-14 00:41

    As std::map is assosiative array one can easily find biggest or smallest key very easily. By defualt compare function is less(<) operator so biggest key will be last element in map. Similarly if someone has different requirement anyone can modify compare function while declaring map.

    std::map< key, Value, compare< key,Value > >

    By default compare=std::less

提交回复
热议问题