【发布时间】:2017-05-02 09:01:00
【问题描述】:
我通过upper_bound 在std::map<int, X> 中找到某个点,然后从这一点开始向后迭代。我的代码看起来像:
MAP::reverse_iterator iter;
iter = _map.upper_bound(value); // Does not compile because upper_bound is not reverse_iterator
while(iter != rbegin()){
// logic
--iter;
}
我得到一个编译错误,因为upper_bound() 没有返回reverse_iterator。
解决这个问题的最佳方法是什么?
【问题讨论】:
-
将迭代器转换为反向迭代器?
-
@NathanOliver 谢谢没有意识到这是可能的。如果你把它作为答案,我会接受。