std :: map中的最后一个键 [英] last key in a std::map

查看:770
本文介绍了std :: map中的最后一个键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找std :: map的最高键值(由比较运算符定义)。

I am looking for the highest key value (a defined by the comparison operator) of a std::map.

这保证是

map.rbegin()->first

(我在反向迭代器上有点不稳定,在std :: map的实现中有多少自由)

(I am a bit shaky on reverse iterators, and how much freedom there is in the implementation of std::map)

如果没有,请指教。我不能更改数据结构。

If not, please advise. I cannot change the data structure.

推荐答案

是的。 Map是一个排序的容器,反向迭代器必须返回它们的键的反向(即递减)顺序的元素。

Yes. Map is a sorted container, the reverse iterator must return the elements in reverse (i.e. decreasing) order of their keys.

这篇关于std :: map中的最后一个键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆